From f141777d52d79c995207d57299075a10d420aeb5 Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 5 Jan 2022 11:54:49 +0100 Subject: [PATCH 1/6] Change thumbnail generation strategy --- bookwyrm/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index f2068a16b..0fe212321 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -190,6 +190,8 @@ USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)" # Imagekit generated thumbnails ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False) IMAGEKIT_CACHEFILE_DIR = "thumbnails" +#IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = "imagekit.cachefiles.backends.Celery" +IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = "imagekit.cachefiles.strategies.Optimistic" # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ From a54995eb9d77863bf93d1ac01c05ee4fd822d6e1 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 8 Jan 2022 17:41:44 +0100 Subject: [PATCH 2/6] Add new complete strategy --- bookwyrm/settings.py | 2 +- bookwyrm/thumbnail_generation.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 bookwyrm/thumbnail_generation.py diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 0fe212321..4d38e0827 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -191,7 +191,7 @@ USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)" ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False) IMAGEKIT_CACHEFILE_DIR = "thumbnails" #IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = "imagekit.cachefiles.backends.Celery" -IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = "imagekit.cachefiles.strategies.Optimistic" +IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = "bookwyrm.thumbnail_generation.Strategy" # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ diff --git a/bookwyrm/thumbnail_generation.py b/bookwyrm/thumbnail_generation.py new file mode 100644 index 000000000..fb9b9c386 --- /dev/null +++ b/bookwyrm/thumbnail_generation.py @@ -0,0 +1,14 @@ +class Strategy: + """ + A strategy that generates the image on source saved (Optimistic), + but also on demand, for old images (JustInTime). + """ + + def on_source_saved(self, file): + file.generate() + + def on_existence_required(self, file): + file.generate() + + def on_content_required(self, file): + file.generate() From 656e0b84ebd5b13babc69e7a9b462d89d92e28a4 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 8 Jan 2022 17:42:25 +0100 Subject: [PATCH 3/6] Fix --- bookwyrm/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 4d38e0827..143190081 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -190,7 +190,7 @@ USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)" # Imagekit generated thumbnails ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False) IMAGEKIT_CACHEFILE_DIR = "thumbnails" -#IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = "imagekit.cachefiles.backends.Celery" +# IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = "imagekit.cachefiles.backends.Celery" IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = "bookwyrm.thumbnail_generation.Strategy" # Static files (CSS, JavaScript, Images) From 12ea1910b464dcf00341dc693fa33dc752d9e8a1 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 8 Jan 2022 17:47:45 +0100 Subject: [PATCH 4/6] Add docstrings --- bookwyrm/thumbnail_generation.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bookwyrm/thumbnail_generation.py b/bookwyrm/thumbnail_generation.py index fb9b9c386..1596e6ab3 100644 --- a/bookwyrm/thumbnail_generation.py +++ b/bookwyrm/thumbnail_generation.py @@ -1,14 +1,18 @@ +"""thumbnail generation strategy for django-imagekit""" class Strategy: """ A strategy that generates the image on source saved (Optimistic), but also on demand, for old images (JustInTime). """ - def on_source_saved(self, file): + def on_source_saved(self, file): # pylint: disable=no-self-use + """What happens on source saved""" file.generate() - def on_existence_required(self, file): + def on_existence_required(self, file): # pylint: disable=no-self-use + """What happens on existence required""" file.generate() - def on_content_required(self, file): + def on_content_required(self, file): # pylint: disable=no-self-use + """What happens on content required""" file.generate() From 705c4cd6360c26c805d734072cd108a49ac76755 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 8 Jan 2022 17:54:03 +0100 Subject: [PATCH 5/6] Update thumbnail_generation.py --- bookwyrm/thumbnail_generation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/thumbnail_generation.py b/bookwyrm/thumbnail_generation.py index 1596e6ab3..64f7ebefb 100644 --- a/bookwyrm/thumbnail_generation.py +++ b/bookwyrm/thumbnail_generation.py @@ -1,4 +1,6 @@ """thumbnail generation strategy for django-imagekit""" + + class Strategy: """ A strategy that generates the image on source saved (Optimistic), From 734da710374420e48ba49f0ce0dd69002df5e47a Mon Sep 17 00:00:00 2001 From: Joachim Date: Sun, 9 Jan 2022 10:36:06 +0100 Subject: [PATCH 6/6] Remove backend setting --- bookwyrm/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 143190081..8762f8211 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -190,7 +190,6 @@ USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)" # Imagekit generated thumbnails ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False) IMAGEKIT_CACHEFILE_DIR = "thumbnails" -# IMAGEKIT_DEFAULT_CACHEFILE_BACKEND = "imagekit.cachefiles.backends.Celery" IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = "bookwyrm.thumbnail_generation.Strategy" # Static files (CSS, JavaScript, Images)