mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 21:11:16 +00:00
Caches query for landing page books
This commit is contained in:
parent
e8c830750a
commit
0a182e8150
5 changed files with 21 additions and 22 deletions
|
@ -1,6 +1,8 @@
|
||||||
{% extends 'landing/layout.html' %}
|
{% extends 'landing/layout.html' %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load cache %}
|
{% load cache %}
|
||||||
|
{% load bookwyrm_tags %}
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
|
|
||||||
<div class="block is-hidden-tablet">
|
<div class="block is-hidden-tablet">
|
||||||
|
@ -9,6 +11,7 @@
|
||||||
|
|
||||||
{% get_current_language as LANGUAGE_CODE %}
|
{% get_current_language as LANGUAGE_CODE %}
|
||||||
{% cache 60 * 60 LANGUAGE_CODE %}
|
{% cache 60 * 60 LANGUAGE_CODE %}
|
||||||
|
{% get_landing_books as books %}
|
||||||
<section class="tile is-ancestor">
|
<section class="tile is-ancestor">
|
||||||
<div class="tile is-vertical is-6">
|
<div class="tile is-vertical is-6">
|
||||||
<div class="tile is-parent">
|
<div class="tile is-parent">
|
||||||
|
|
|
@ -112,6 +112,24 @@ def latest_read_through(book, user):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=False)
|
||||||
|
def get_landing_books():
|
||||||
|
"""list of books for the landing page"""
|
||||||
|
return list(
|
||||||
|
set(
|
||||||
|
models.Edition.objects.filter(
|
||||||
|
review__published_date__isnull=False,
|
||||||
|
review__deleted=False,
|
||||||
|
review__user__local=True,
|
||||||
|
review__privacy__in=["public", "unlisted"],
|
||||||
|
)
|
||||||
|
.exclude(cover__exact="")
|
||||||
|
.distinct()
|
||||||
|
.order_by("-review__published_date")[:6]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def mutuals_count(context, user):
|
def mutuals_count(context, user):
|
||||||
"""how many users that you follow, follow them"""
|
"""how many users that you follow, follow them"""
|
||||||
|
|
|
@ -16,7 +16,6 @@ from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from bookwyrm import emailing, forms, models
|
from bookwyrm import emailing, forms, models
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
from bookwyrm.views import helpers
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable= no-self-use
|
# pylint: disable= no-self-use
|
||||||
|
@ -174,7 +173,6 @@ class InviteRequest(View):
|
||||||
data = {
|
data = {
|
||||||
"request_form": form,
|
"request_form": form,
|
||||||
"request_received": received,
|
"request_received": received,
|
||||||
"books": helpers.get_landing_books(),
|
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "landing/landing.html", data)
|
return TemplateResponse(request, "landing/landing.html", data)
|
||||||
|
|
||||||
|
|
|
@ -153,24 +153,6 @@ def is_blocked(viewer, user):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_landing_books():
|
|
||||||
"""list of books for the landing page"""
|
|
||||||
|
|
||||||
return list(
|
|
||||||
set(
|
|
||||||
models.Edition.objects.filter(
|
|
||||||
review__published_date__isnull=False,
|
|
||||||
review__deleted=False,
|
|
||||||
review__user__local=True,
|
|
||||||
review__privacy__in=["public", "unlisted"],
|
|
||||||
)
|
|
||||||
.exclude(cover__exact="")
|
|
||||||
.distinct()
|
|
||||||
.order_by("-review__published_date")[:6]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def load_date_in_user_tz_as_utc(date_str: str, user: models.User) -> datetime:
|
def load_date_in_user_tz_as_utc(date_str: str, user: models.User) -> datetime:
|
||||||
"""ensures that data is stored consistently in the UTC timezone"""
|
"""ensures that data is stored consistently in the UTC timezone"""
|
||||||
if not date_str:
|
if not date_str:
|
||||||
|
|
|
@ -3,7 +3,6 @@ from django.template.response import TemplateResponse
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import forms
|
from bookwyrm import forms
|
||||||
from bookwyrm.views import helpers
|
|
||||||
from bookwyrm.views.feed import Feed
|
from bookwyrm.views.feed import Feed
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +35,5 @@ class Landing(View):
|
||||||
data = {
|
data = {
|
||||||
"register_form": forms.RegisterForm(),
|
"register_form": forms.RegisterForm(),
|
||||||
"request_form": forms.InviteRequestForm(),
|
"request_form": forms.InviteRequestForm(),
|
||||||
"books": helpers.get_landing_books(),
|
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "landing/landing.html", data)
|
return TemplateResponse(request, "landing/landing.html", data)
|
||||||
|
|
Loading…
Reference in a new issue