Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all() from category manager #106

Open
stuartmaxwell opened this issue Jan 23, 2025 · 1 comment
Open

Remove all() from category manager #106

stuartmaxwell opened this issue Jan 23, 2025 · 1 comment
Assignees
Labels
refactor Refactor existing code

Comments

@stuartmaxwell
Copy link
Owner

I don't think .all() is required in the following two methods:

    def get_categories(self: "CategoryManager") -> models.QuerySet:
        """Return the queryset for categories.

        If CACHE_CATEGORIES is set to True, we return the cached queryset.
        """
        if djpress_settings.CACHE_CATEGORIES:
            return self._get_cached_categories()

        return self.all()

    def _get_cached_categories(self: "CategoryManager") -> models.QuerySet:
        """Return the cached categories queryset."""
        queryset = cache.get(CATEGORY_CACHE_KEY)

        if queryset is None:
            queryset = self.all()
            cache.set(CATEGORY_CACHE_KEY, queryset, timeout=None)

        return queryset
@stuartmaxwell stuartmaxwell added the refactor Refactor existing code label Jan 23, 2025
@stuartmaxwell stuartmaxwell self-assigned this Jan 23, 2025
@stuartmaxwell
Copy link
Owner Author

Might be: self.get_queryset() instead. Need to look up which is the better option, or if it matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor existing code
Projects
Status: No status
Development

No branches or pull requests

1 participant