diff --git a/bookmarks/migrations/0043_bookmark_latest_snapshot_id.py b/bookmarks/migrations/0043_bookmark_latest_snapshot_id.py new file mode 100644 index 0000000..39954c7 --- /dev/null +++ b/bookmarks/migrations/0043_bookmark_latest_snapshot_id.py @@ -0,0 +1,30 @@ +# Generated by Django 5.1.1 on 2024-11-12 00:16 + +from django.db import migrations, models + + +def update_latest_snapshots(apps, schema_editor): + Bookmark = apps.get_model("bookmarks", "bookmark") + for bookmark in Bookmark.objects.all(): + snapshots = bookmark.bookmarkasset_set.filter(status="complete").order_by( + "-date_created" + ) + if snapshots: + bookmark.latest_snapshot_id = snapshots[0].id + bookmark.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookmarks", "0042_userprofile_custom_css_hash"), + ] + + operations = [ + migrations.AddField( + model_name="bookmark", + name="latest_snapshot_id", + field=models.IntegerField(blank=True, null=True), + ), + migrations.RunPython(update_latest_snapshots), + ] diff --git a/bookmarks/models.py b/bookmarks/models.py index fe4530b..dc2c169 100644 --- a/bookmarks/models.py +++ b/bookmarks/models.py @@ -62,6 +62,7 @@ class Bookmark(models.Model): # Obsolete field, kept to not remove column when generating migrations website_description = models.TextField(blank=True, null=True) web_archive_snapshot_url = models.CharField(max_length=2048, blank=True) + latest_snapshot_id = models.IntegerField(blank=True, null=True) favicon_file = models.CharField(max_length=512, blank=True) preview_image_file = models.CharField(max_length=512, blank=True) unread = models.BooleanField(default=False) diff --git a/bookmarks/services/tasks.py b/bookmarks/services/tasks.py index a0655fe..8b19c2d 100644 --- a/bookmarks/services/tasks.py +++ b/bookmarks/services/tasks.py @@ -320,6 +320,8 @@ def _create_html_snapshot_task(asset_id: int): asset.file = filename asset.gzip = True asset.save() + asset.bookmark.latest_snapshot_id = asset.id + asset.bookmark.save() logger.info( f"Successfully created HTML snapshot for bookmark. url={asset.bookmark.url}" ) diff --git a/bookmarks/templates/bookmarks/bookmark_list.html b/bookmarks/templates/bookmarks/bookmark_list.html index e115975..1fe2013 100644 --- a/bookmarks/templates/bookmarks/bookmark_list.html +++ b/bookmarks/templates/bookmarks/bookmark_list.html @@ -64,7 +64,14 @@ {% endif %}