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 Wed, 10 Feb 2021 18:36:53 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 6bc97808aa732c3a347d8923c7e043c1d88c19d5
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/model/project.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

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