Make randomid deterministic to improve caching
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
|
||||
from django import template
|
||||
|
||||
@@ -8,4 +7,7 @@ register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def randomid(seed: str = "") -> str:
|
||||
return str(hash(seed + "".join(random.choices(string.ascii_lowercase, k=10))))
|
||||
content_hash = hashlib.sha1(seed.encode()).hexdigest()
|
||||
if seed:
|
||||
return content_hash[:max(0, 10 - len(seed))] + seed
|
||||
return content_hash[:10]
|
||||
|
||||
Reference in New Issue
Block a user