Merge pull request #25309 from ankush/mysql_optimized_naming

perf: optimize hash naming for MySQL storage
This commit is contained in:
Ankush Menat 2024-03-10 21:34:59 +05:30 committed by GitHub
commit 71a73054de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,8 @@
import datetime
import re
import struct
import time
from collections.abc import Callable
from typing import TYPE_CHECKING, Optional
@ -262,7 +264,10 @@ def make_autoname(key="", doctype="", doc="", *, ignore_validate=False):
DE/09/01/00001 where 09 is the year, 01 is the month and 00001 is the series
"""
if key == "hash":
return frappe.generate_hash(length=10)
# Makeshift "ULID": first 4 chars are based on timestamp, other 8 are random
ts = hex(struct.unpack("<Q", struct.pack("<d", time.time()))[0])
return ts[-8:-5] + frappe.generate_hash(length=7)
series = NamingSeries(key)
return series.generate_next_name(doc, ignore_validate=ignore_validate)