mirror of
https://github.com/pretix/pretix.git
synced 2026-05-10 16:04:02 +00:00
CSS generation: Compress cached result with gzip to save redis memory
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||||
# <https://www.gnu.org/licenses/>.
|
# <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
import gzip
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -107,7 +108,10 @@ def compile_scss(object, file="main.scss", fonts=True):
|
|||||||
|
|
||||||
cp = cache.get_or_set('sass_compile_prefix', now().isoformat())
|
cp = cache.get_or_set('sass_compile_prefix', now().isoformat())
|
||||||
css = cache.get('sass_compile_{}_{}'.format(cp, srcchecksum))
|
css = cache.get('sass_compile_{}_{}'.format(cp, srcchecksum))
|
||||||
if not css:
|
if css:
|
||||||
|
if isinstance(css, bytes) and css[0:2] == b'\x1f\x8b':
|
||||||
|
css = gzip.decompress(css).decode()
|
||||||
|
else:
|
||||||
cf = dict(django_libsass.CUSTOM_FUNCTIONS)
|
cf = dict(django_libsass.CUSTOM_FUNCTIONS)
|
||||||
cf['static'] = static
|
cf['static'] = static
|
||||||
css = sass.compile(
|
css = sass.compile(
|
||||||
@@ -117,7 +121,7 @@ def compile_scss(object, file="main.scss", fonts=True):
|
|||||||
)
|
)
|
||||||
cssf = CSSMinFilter(css)
|
cssf = CSSMinFilter(css)
|
||||||
css = cssf.output()
|
css = cssf.output()
|
||||||
cache.set('sass_compile_{}_{}'.format(cp, srcchecksum), css, 600)
|
cache.set('sass_compile_{}_{}'.format(cp, srcchecksum), gzip.compress(css.encode()), 600)
|
||||||
|
|
||||||
checksum = hashlib.sha1(css.encode('utf-8')).hexdigest()
|
checksum = hashlib.sha1(css.encode('utf-8')).hexdigest()
|
||||||
return css, checksum
|
return css, checksum
|
||||||
|
|||||||
Reference in New Issue
Block a user