allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kentontay...@apache.org
Subject [allura] 01/01: SF-5746 use project icon file hash for cache busting
Date Tue, 16 Feb 2021 13:40:06 GMT
This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch kt/icon-hash
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 57ae2c4ee697a3c60d3c1eb4b9b67cc01c4b7be0
Author: Kenton Taylor <ktaylor@slashdotmedia.com>
AuthorDate: Wed Feb 10 18:34:58 2021 +0000

    SF-5746 use project icon file hash for cache busting
---
 Allura/allura/ext/admin/admin_main.py |  2 +-
 Allura/allura/model/project.py        | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index a2384bd..26380b2 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -335,7 +335,7 @@ class ProjectAdminController(BaseController):
             c.project.removal_changed_date = datetime.utcnow()
         if 'delete_icon' in kw:
             M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
-            c.project.set_tool_data('allura', icon_original_size=None)
+            c.project.set_tool_data('allura', icon_original_size=None, icon_sha256=None)
             M.AuditLog.log('remove project icon')
             g.post_event('project_updated')
             redirect('overview')
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 68585b7..5819a8f 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -21,6 +21,8 @@ from __future__ import absolute_import
 import logging
 from calendar import timegm
 from collections import Counter, OrderedDict
+from hashlib import sha256
+
 from datetime import datetime
 from copy import deepcopy
 import six.moves.urllib.request
@@ -380,8 +382,18 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         )
         # store the dimensions so we don't have to read the whole image each time we need
to know
         icon_orig_img = PIL.Image.open(icon_orig.rfile())
+
         self.set_tool_data('allura', icon_original_size=icon_orig_img.size)
 
+        try:
+            # calc and save icon file hash, for better cache busting purposes
+            file_input.seek(0)
+            file_bytes = file_input.read()
+            file_sha256 = sha256(file_bytes).hexdigest()
+            self.set_tool_data('allura', icon_sha256=file_sha256)
+        except Exception as ex:
+            log.exception('Failed to calculate sha256 for icon file for {}'.format(self.shortname))
+
     @property
     def icon(self):
         return self.icon_sized(DEFAULT_ICON_WIDTH)


Mime
View raw message