Commit graph

176 commits

Author SHA1 Message Date
Mihir Kandoi
922c1b812d
fix(document naming): customer parser should be checked before anything else (#35586) 2026-01-05 13:44:32 +05:30
Akhil Narang
8723a2b6ee
fix: ruff fixes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2025-12-22 21:06:48 +05:30
Rohit Waghchaure
2b0ee31cb4 fix: read lock applied while fetching the current value from the tabSeries 2025-11-18 11:51:10 +05:30
PUGAZHENDHI V
4c1a61f085
fix: validate dot in numeric placeholders (#33739)
* fix: validate dot in numeric placeholders

* fix: failed test cases
2025-08-25 11:58:43 +05:30
Ankush Menat
f9ff807e4c
refactor: Rename get_settings -> get_single_value (#32840)
Not all single doctypes are settings, so this is better. Implicit
caching is fine, same is done for `db` APIs on singles. We *should* aim
for 100% correctness of caching implementation, especially for singles.

Thanks to @netchampfaris for the suggestion.
2025-06-09 04:20:29 +00:00
Ankush Menat
caf415f13e
feat: get_settings (#32821)
* feat: get_settings

get_cached_value doesn't work well with singles because you either need
to pass `None` or repeat doctype name... both are awekward and easy to
shoot yourself in foot with.

* refactor: Use cached settings
2025-06-06 18:34:17 +05:30
Mikie Sterner
0596e1c6c1 feat: Add Julian Day to Auto Naming series 2025-04-18 13:20:14 -06:00
Akhil Narang
8a758365eb
Revert "Merge pull request #28363 from frappe/expr-series" (#31202)
This reverts commit 91d553c9cf, reversing
changes made to d17136cd04.
2025-02-10 06:46:45 +00:00
Ankush Menat
9b79dfeb7b
perf: "random" naming to improve concurrency and locality (#30053)
This feels overengineered and it kinda is, but other efforts to
inroduce sequential naming/UUID naming haven't been that fruitful
either.

10 character random "hash" i now changed to.

1. first character - last character in UUID4 ID of request/job
2. three characters - derived from current timestamp.
4. 6 characters - random data.

This satisfies all three requirements:

1. Readers - temporal locality should result in spatial locality on disk. (fewer pages accessed)
2. Single writer - temporal locality should result in spatial locality. (fewer dirty pages)
3. Multiple writers - temporal locality should NOT result in spatial locality. (less lock contention)

Mostly concludes https://github.com/frappe/frappe/pull/25309 and https://github.com/frappe/frappe/pull/28349

Rough probabiliy numbers

Assumptions:
- Unique per worker prefix - 16 (uuid's base16 version)
- Rough time spent generating names - 10% of request (very very conservative estimate)

Probability(collision) = P(at least one prefix collision) * P(time collision)
Probability(collision) = (1 - p(all different)) * 10%
Probability(collision) = (1 - (16! / 16-N! )/ 16^N ) * 10%

| N (concurrency) | Probability(collision) |
| 1  |    0.0% |
| 2  |    0.6% |
| 3  |    1.8% |
| 4  |    3.3% |
| 5  |    5.0% |
| 6  |    6.6% |
| 7  |    7.9% |
| 8  |    8.8% |
2025-01-25 07:04:09 +00:00
Sumit Bhanushali
62d8d5875a fix(NamingExpression): series should be seperate for different expressions instead of global 2024-11-04 14:38:52 +05:30
Ankush Menat
16407a50ec
fix: Excessive gap locking from hash naming (#28349)
Because of large common prefix hash naming becomes "too sequential" when
doing a lot of concurrent writes.

I don't know a good tradeoff between both use cases:
1. Lots of reads - prefers large shared prefix.
2. Lots of writes - prefers small shared prefix.

But as of now this punishes writes too badly in form of excessive
locking. Until a better fix is found, it's better to keep it prefix free.

---

A better fix would be a tradeoff of between these two:

1. Reads - temporal locality should result in spatial locality on disk.
2. Writes - temporal locality should NOT result in spatial locality.

temporal locality = data inserted around same time
spatial locality = data sits next to each other in DB pages.

This can be achieved by adding a small request/job specific part to
prefix so each concurrent request has it's own different locality when
writing data.
2024-11-01 06:18:22 +00:00
Ankush Menat
1ec4d658fc fix: Allow setting UUID to application code 2024-03-29 19:02:28 +05:30
Ankush Menat
6c79a13641 feat: UUID naming support 2024-03-29 19:02:28 +05:30
Ankush Menat
adf24b24d4
perf: use base32 space for random names instead of base16 (#25497) 2024-03-17 20:02:57 +05:30
Ankush Menat
495273dcf9 fix: faster change of hash prefix 2024-03-10 21:48:56 +05:30
Ankush Menat
665f1fdf79 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.
2024-03-10 21:22:36 +05:30
Akhil Narang
3f1e19de85
refactor(treewide): enable RUF rules
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-21 16:20:28 +05:30
Akhil Narang
26ae0f3460
fix: ruff fixes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-07 17:04:31 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Hussain Nagaria
8d2137c265 docs: consistent doc strings 2023-12-18 18:27:39 +05:30
Ankush Menat
730e906dfd
refactor!: remove implicit primary key from logs (#22209) 2023-08-26 16:01:47 +05:30
Ankush Menat
79392260d4
fix: autoincr caching and clear site cache after restore (#22079)
* fix: remove hazardous cache for autoincr

* fix: move cache to redis

* fix: clear all redis cache after restoring a site
2023-08-17 11:11:27 +05:30
mergify[bot]
fd10ab25cc
Merge pull request #22003 from gavindsouza/refactor-doc-bits
refactor: Use single query to delete child rows on doc.save
2023-08-11 06:45:07 +00:00
Gavin D'souza
84f134a683
fix: Add "better" typing hints 2023-08-11 11:45:47 +05:30
barredterra
b553ed98d8 refactor: inline immediately returned variable
Inline a variable to a return in the case when the
variable being declared is immediately returned
2023-08-08 18:09:49 +02:00
Ankush Menat
8817c228a2 fix: filter schema name on mariadb 2023-08-04 14:33:17 +05:30
Ankush Menat
fd15ab5329 fix: revert pg incompatible change 2023-08-04 14:13:36 +05:30
Ankush Menat
c4230f8760
fix: autoincr status per doctype (#21918)
* fix: autoincr status per doctype

closes https://github.com/frappe/frappe/issues/21386

* chore: Check autoincremented on the database currently being used.

* refactor: Styling and space fix

---------

Co-authored-by: Athul Cyriac Ajay <athul8720@gmail.com>
2023-08-04 13:59:39 +05:30
Deepesh Garg
e32e74f2f1
feat: Custom naming series parser via hooks (#21690)
* feat: Custom naming series parser via hooks

* chore: use assignment operatot

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>

* test: Unit test for custom parser

* test: Unit test for custom parser

---------

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
2023-07-16 12:57:40 +05:30
Ankush Menat
adf30693a9 ci: update pyupgrade 2023-07-14 14:24:08 +05:30
Sagar Vora
b4f1a2328b
fix: ignore naming series validation when generating repeated address name (#21568) 2023-07-10 10:51:55 +05:30
Dany Robert
4f3c0f6e99
feat: configurable amended document naming (#21414)
* feat: configurable amendment naming

* patch: set default amend naming

* chore: linters and document filter

* test: amended document naming

* refactor: use set_single_value

* chore: typo, fix copy

* fix(UX): move action button below table

* refactor: Series Counter -> Default Naming

The behaviour in this PR doesn't necessarily mean to apply naming series
it can be:
- Naming Series
- hash
- Naming Rule
- Some code

So the name was misleading.

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-06-20 21:37:08 +05:30
Ritwik Puri
2e2c8316c6
fix: use sentinel value for checking existence of key in doc while parsing naming series (#20994) 2023-05-15 14:58:14 +05:30
Ritwik Puri
4bd32bcf04
fix: naming part should be empty if field is empty (#20978) 2023-05-14 00:41:12 +05:30
Ankush Menat
5348dd1f29 fix: Migration fails while inserting docfield
When migrating base doctypes we need to insert docfield which triggers
 document naming rule code and document naming rule doesn't yet exists
 cause that's what we are trying to migrate.

Fix: skip naming rule on bootstrapped doctypes.
2023-02-03 13:28:59 +05:30
Anand Baburajan
6554919f1e
fix: improve invalid naming series message (#19711)
* fix: show the invalid naming series in special chars error msg

* chore: translations

[skip ci]
2023-01-23 15:00:04 +05:30
Ankush Menat
f34f7030a3 refactor: remove txt param from generate_hash use 2022-11-10 11:56:48 +05:30
Daizy
78d30905ac refactor: get_doctype_map() using single query and use generator for caching 2022-11-02 09:58:34 +00:00
Daizy
28a124ca47 perf: cache document naming rule to avoid multiple db call 2022-11-02 09:58:34 +00:00
Ankush Menat
8cca50bf26
refactor: remove naming case feature (#18672)
This has never worked since 2016... which can mean two things:
- No one really uses this.
- If I fix this now suddenly people will find different behaviour in
  naming because `name_case` is selected in some doctypes (but never
  tested)
2022-10-31 11:23:49 +05:30
Anand Baburajan
feb198a019
docs: fix make_autoname example (#18354) 2022-10-10 21:04:35 +05:30
Ritwik Puri
66a31917f7
refactor(minor): reorder and remove unnecessary branches in set_new_name (#18243) 2022-09-29 16:23:55 +05:30
Ankush Menat
95f67b8de8
fix: ignore empty part in naming series (#17508)
on v13 doc.get("") returns entire doc dictionary, this gets strigified
and becomes a problem for naming.
2022-07-14 13:14:58 +05:30
Ankush Menat
111060224b fix: naming series tool doesn't load if missing numbers 2022-07-07 17:38:52 +05:30
Ankush Menat
60c4819373
refactor: safer binding of outer scope in closures (#17389) 2022-07-04 13:39:56 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30
vishdha
27f2cdf016 chore: remove unused code 2022-06-17 13:59:21 +05:30
vishdha
ea18460cc2 fix: date_field not able to fetch in _format_naming autoname 2022-06-17 13:59:21 +05:30
Gavin D'souza
b696fa6da5 perf: Pre-compile and re-use regexp pattern
Converted all possible usages of re.* that weren't compiling the regex
separately and re-using it. Separated out the compiled patterns as
global variables. Repetitive patterns could be made DRY-er.

Would be nicer to have all regexes in a single module so that we could
re-use better, keep track of outdated, and keep checks for possible
reDos' etc
2022-06-08 14:07:38 +05:30
Ankush Menat
462aa20386
fix: naming using doc fields (#17040) 2022-05-31 19:55:34 +05:30