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

Sql-optimisation #76

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "djpress"
version = "0.13.0"
version = "0.13.1"
description = "A blog application for Django sites, inspired by classic WordPress."
readme = "README.md"
requires-python = ">=3.10"
Expand Down Expand Up @@ -96,7 +96,7 @@ include = ["src/djpress/*"]
omit = ["*/tests/*", "*/migrations/*"]

[tool.bumpver]
current_version = "0.13.0"
current_version = "0.13.1"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "👍 bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion src/djpress/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""djpress module."""

__version__ = "0.13.0"
__version__ = "0.13.1"
4 changes: 2 additions & 2 deletions src/djpress/models/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PagesManager(models.Manager):

def get_queryset(self: "PagesManager") -> models.QuerySet:
"""Return the queryset for pages."""
return super().get_queryset().filter(post_type="page")
return super().get_queryset().filter(post_type="page").select_related("parent")

def get_published_pages(self: "PagesManager") -> models.QuerySet:
"""Return all published pages.
Expand All @@ -40,7 +40,7 @@ def get_published_pages(self: "PagesManager") -> models.QuerySet:
- All parent pages must also be published.
"""
return Post.page_objects.filter(
pk__in=[page.pk for page in self.get_queryset().select_related("parent") if page.is_published],
pk__in=[page.pk for page in self.get_queryset() if page.is_published],
).order_by("menu_order", "title", "-date")

def get_published_page_by_slug(
Expand Down
2 changes: 1 addition & 1 deletion src/djpress/templatetags/djpress_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def blog_pages(
Returns:
str: The pages of the blog.
"""
pages: models.QuerySet[Post] = get_pages()
pages = Post.page_objects.get_published_pages()

if not pages:
return ""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_templatetags_djpress_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def test_get_posts(test_post1, test_long_post1, test_post2, test_post3):
assert list(djpress_tags.get_posts()) == list(posts)


@pytest.mark.django_db
def test_get_pages(test_page1, test_page2):
pages = [test_page1, test_page2]

assert list(djpress_tags.get_pages()) == pages


@pytest.mark.django_db
def test_have_posts_single_post(test_post1):
"""Return a list of posts in the context."""
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.