From 665f1fdf7935637642f66df45391c39afda7e3df Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 10 Mar 2024 18:01:44 +0530 Subject: [PATCH] perf: optimize hash naming for MySQL storage Random names can send rows all over the place, typically documents created closer in time should live closer on mysql pages too. --- frappe/model/naming.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 7d5d63578a..658d94f702 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -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("