1
0
Fork 0

fix snapshot icon caching and ordering

This commit is contained in:
Nick Sweeting 2021-04-01 02:22:15 -04:00
parent fc5d99b4b4
commit 59d5423483
3 changed files with 6 additions and 6 deletions

View file

@ -12,6 +12,7 @@ from ..config import ARCHIVE_DIR, ARCHIVE_DIR_NAME
from ..system import get_dir_size
from ..util import parse_date, base_url, hashurl
from ..index.schema import Link
from ..index.html import snapshot_icons
from ..extractors import get_default_archive_methods, ARCHIVE_METHODS_INDEXING_PRECEDENCE
EXTRACTORS = [(extractor[0], extractor[0]) for extractor in get_default_archive_methods()]
@ -125,6 +126,9 @@ class Snapshot(models.Model):
return tags_str
return cache.get_or_set(cache_key, calc_tags_str)
def icons(self) -> str:
return snapshot_icons(self)
@cached_property
def bookmarked(self):
return parse_date(self.timestamp)

View file

@ -209,7 +209,7 @@ class PublicIndexView(ListView):
template_name = 'public_index.html'
model = Snapshot
paginate_by = SNAPSHOTS_PER_PAGE
ordering = ['title']
ordering = ['-added']
def get_context_data(self, **kwargs):
return {
@ -223,10 +223,6 @@ class PublicIndexView(ListView):
query = self.request.GET.get('q')
if query:
qs = qs.filter(Q(title__icontains=query) | Q(url__icontains=query) | Q(timestamp__icontains=query) | Q(tags__name__icontains=query))
for snapshot in qs:
# lazy load snapshot icons, otherwise it will load icons for entire index at once
snapshot.icons = lambda: snapshot_icons(snapshot)
return qs
def get(self, *args, **kwargs):

View file

@ -116,7 +116,7 @@ def render_django_template(template: str, context: Mapping[str, str]) -> str:
def snapshot_icons(snapshot) -> str:
cache_key = f'{str(snapshot.id)[:12]}-{(snapshot.updated or snapshot.added).timestamp()}-snapshot-icons'
cache_key = f'{snapshot.id}-{(snapshot.updated or snapshot.added).timestamp()}-snapshot-icons'
def calc_snapshot_icons():
from core.models import EXTRACTORS