mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-29 22:15:21 -04:00
fix snapshot icon caching and ordering
This commit is contained in:
parent
fc5d99b4b4
commit
59d5423483
3 changed files with 6 additions and 6 deletions
|
@ -12,6 +12,7 @@ from ..config import ARCHIVE_DIR, ARCHIVE_DIR_NAME
|
||||||
from ..system import get_dir_size
|
from ..system import get_dir_size
|
||||||
from ..util import parse_date, base_url, hashurl
|
from ..util import parse_date, base_url, hashurl
|
||||||
from ..index.schema import Link
|
from ..index.schema import Link
|
||||||
|
from ..index.html import snapshot_icons
|
||||||
from ..extractors import get_default_archive_methods, ARCHIVE_METHODS_INDEXING_PRECEDENCE
|
from ..extractors import get_default_archive_methods, ARCHIVE_METHODS_INDEXING_PRECEDENCE
|
||||||
|
|
||||||
EXTRACTORS = [(extractor[0], extractor[0]) for extractor in get_default_archive_methods()]
|
EXTRACTORS = [(extractor[0], extractor[0]) for extractor in get_default_archive_methods()]
|
||||||
|
@ -125,6 +126,9 @@ class Snapshot(models.Model):
|
||||||
return tags_str
|
return tags_str
|
||||||
return cache.get_or_set(cache_key, calc_tags_str)
|
return cache.get_or_set(cache_key, calc_tags_str)
|
||||||
|
|
||||||
|
def icons(self) -> str:
|
||||||
|
return snapshot_icons(self)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def bookmarked(self):
|
def bookmarked(self):
|
||||||
return parse_date(self.timestamp)
|
return parse_date(self.timestamp)
|
||||||
|
|
|
@ -209,7 +209,7 @@ class PublicIndexView(ListView):
|
||||||
template_name = 'public_index.html'
|
template_name = 'public_index.html'
|
||||||
model = Snapshot
|
model = Snapshot
|
||||||
paginate_by = SNAPSHOTS_PER_PAGE
|
paginate_by = SNAPSHOTS_PER_PAGE
|
||||||
ordering = ['title']
|
ordering = ['-added']
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
return {
|
return {
|
||||||
|
@ -223,10 +223,6 @@ class PublicIndexView(ListView):
|
||||||
query = self.request.GET.get('q')
|
query = self.request.GET.get('q')
|
||||||
if query:
|
if query:
|
||||||
qs = qs.filter(Q(title__icontains=query) | Q(url__icontains=query) | Q(timestamp__icontains=query) | Q(tags__name__icontains=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
|
return qs
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
|
|
|
@ -116,7 +116,7 @@ def render_django_template(template: str, context: Mapping[str, str]) -> str:
|
||||||
|
|
||||||
|
|
||||||
def snapshot_icons(snapshot) -> 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():
|
def calc_snapshot_icons():
|
||||||
from core.models import EXTRACTORS
|
from core.models import EXTRACTORS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue