Commit graph

2577 commits

Author SHA1 Message Date
Sagar Vora
ffba20a160 perf: faster _init_child 2025-02-25 14:01:09 +05:30
Sagar Vora
aae5860efc perf: faster init_valid_columns 2025-02-25 13:20:35 +05:30
Ankush Menat
7721fdb054
fix: clear cache using client_cache (#31420)
It's faster than relying on indirect invalidations. This was avoided
before only because delete_keys didn't exist on client_cache.
2025-02-25 06:43:39 +00:00
Sagar Vora
c31cb69d5c fix: update reserved keywords 2025-02-25 12:00:51 +05:30
Sagar Vora
99574a74e2
Merge pull request #31400 from sagarvora/better-table-fieldnames 2025-02-25 10:43:29 +05:30
Ankush Menat
efee329adf
fix: Unlock old locks automatically (#31411) 2025-02-24 13:49:08 +00:00
Sagar Vora
26b5d8de15 perf: better _table_fieldnames cache 2025-02-24 17:41:00 +05:30
Sagar Vora
a811aecbc2
Merge pull request #31395 from sagarvora/no-new-weakref 2025-02-24 16:16:14 +05:30
Ankush Menat
dd44b3dba6
perf: cast int-link field filters to string (#31396)
Comparing varchar field with ints makes indexes unusable in MariaDB.

This PR is just one small fix for DB query, similar fixes won't be made
for DB APIs which do not assume anything about database schema.
2025-02-24 10:39:55 +00:00
Sagar Vora
fc7202ade4 perf: dont create a new weakref.ref for each child 2025-02-24 15:57:42 +05:30
Sagar Vora
b381cc4874
Merge branch 'develop' into ref-docstatus 2025-02-24 15:22:06 +05:30
Sagar Vora
be5e856dd9
Merge pull request #31391 from sagarvora/perf-nosingledispatchmethod 2025-02-24 15:21:05 +05:30
Sagar Vora
bb1080dfac perf: dont use singledispatchmethod 2025-02-24 15:11:14 +05:30
Sagar Vora
fcf657ba80 perf: improved DocStatus API and other minor improvements 2025-02-24 12:51:10 +05:30
Ankush Menat
37da1d43bd
fix: remove duplicate clear_cache calls (#31374)
This is internally handled in clear_document_cache

Fix was only required for websitegenerator specific things.
2025-02-21 08:54:05 +00:00
Sagar Vora
6ef67c7a38
Merge pull request #31357 from sagarvora/reqd-fields-only 2025-02-20 17:57:29 +05:30
Sagar Vora
ece9b6396d perf: get reqd fields only 2025-02-20 17:47:35 +05:30
Sagar Vora
2f9f659fcb perf(DX): always cache controllers 2025-02-20 17:43:12 +05:30
Ankush Menat
4997e5d223
fix: clear cache after db transaction ends (#31315)
This reduces probability of stale cache, but it's still very easily
possible because of repeatable read (!)
2025-02-19 11:44:37 +00:00
Sagar Vora
f4062b4d7a fix: ensure consistent error in response 2025-02-19 12:10:59 +05:30
Ankush Menat
7f0394bf86
fix: short-circuit large table checks (#31223)
This can become super slow on child tables, so first check if it's worth "checking" data.
2025-02-11 10:09:29 +00:00
Ankush Menat
ef3b0ef008
perf: Only filter last 3 months of data by default on large tables (#31216)
Applying something basic like `order id like xyz` filter can result in
full table scan on years of data. This isn't necessary most of the time.

Interactive queries are usually done on recent data, so add this filter
to ensure only recent data is checked first.

Users can remove this filter if they want to.
2025-02-11 09:24:08 +00: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
Sandeep Kakde
165968714d
fix: update cache key for table_columns to new format (#31179) 2025-02-07 17:19:02 +05:30
Ankush Menat
e3ce05b57e
perf: use client cache for notifications (#31094) 2025-02-04 09:24:30 +00:00
Ankush Menat
8eafe67805 feat: share table size heuristic with meta 2025-02-03 09:29:31 +05:30
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
barredterra
015c9425ed Revert "fix: don't skip perm check when Apply Strict User Permissions is enabled (#29916)"
This reverts commit 4a0ccf6d76.
2025-01-24 19:56:44 +01:00
Raffael Meyer
4a0ccf6d76
fix: don't skip perm check when Apply Strict User Permissions is enabled (#29916) 2025-01-24 14:43:46 +05:30
Ankush Menat
4e4972fe2d
refactor: Use @cached_property (#29212) 2025-01-17 06:09:05 +00:00
Ankush Menat
e6bad301b8 refactor: Use @cached_property instead of implmenting it 2025-01-16 19:19:56 +05:30
Ankush Menat
b3859d9fa3 fix: Don't assume homogeneous data in meta tables
Steps to reproduce:
- enable developer mode (doesn't happen in prod)
- Save a document with set only once fields
- Reload the page (requests meta again which is now polluted)

This is new category of bug surfaced because meta objects now live
longer than request and all kinds of weird `self._cached_property`
starts getting serialized.

Co-Authored-By: ruthra kumar <ruthra@erpnext.com>
2025-01-16 19:10:16 +05:30
Ankush Menat
9c2bd23606
fix: don't override setstate (#29194)
Meta sometimes break because of this, I don't quite know why but this
change isn't that useful, so best to revert it for now.
2025-01-16 15:50:47 +05:30
Ankush Menat
fdba41c682
perf: misc client cache improvements (#29070)
* perf: Reduce penalty for lack of redis connection

If redis isn't running than this client cache is slower than default
implementation because of the extra locking overhead.

* test: update perf redis counts

* perf: cache table columns in client-cache

* fix: race condition on cache-client_cache init

Rare but apparant in synthetic benchmarks.

Cache is set but client cache is still being initialized then request
will fail.

* perf: Don't run notifications when loading document

WHAT?

* fix: use cached doc to repopulate

* perf: reduce get_meta calls
2025-01-07 16:14:43 +05:30
Ankush Menat
55ae5615d0 fix: clear all meta cache only when doctype is not specified 2025-01-06 18:57:57 +05:30
Ankush Menat
e7139a1395 perf: store meta in client cache 2025-01-06 18:57:57 +05:30
Ankush Menat
546260162d perf: Skip link checking on internal deletes
These are deletes that aren't user triggered and these documents are
typically never "linked" somewhere else. So skip all expensive link /
dynamic link checks.
2025-01-06 11:48:19 +05:30
ruthra kumar
cb89393d24 refactor: temporary key for child rows 2025-01-02 15:33:15 +05:30
Akhil Narang
2af6eedec9
Merge pull request #28873 from krantheman/fix-html-editor
fix(HTML Editor): extraction of images
2024-12-24 16:14:00 +05:30
Ankush Menat
3cb8a9e2e4
perf: cache dynamic links map in Redis (#28878)
Note about correctness: Once site has seen enough usage this map will rarely change. So the
problem of "cache inconsistency" is very rare, still care is taken to
avoid possible cache inconsistencies.
2024-12-23 19:43:05 +05:30
krantheman
bb38c62642 fix(HTML Editor docfield): extraction of images 2024-12-23 14:55:05 +05:30
Ankush Menat
17cc356915
perf: speed up flt by 1.06x and get_system_settings by 1.32x (#28841)
* perf: resolve rounding method once

When rounding method is explcitly specified it's 1.4x faster.

* perf: reorder checks

Bankers rounding is default and most common now

* perf: speedup get_system_settings
2024-12-19 14:38:45 +00:00
Ankush Menat
7dd15e3613
perf: speedup pickling of document objects (#28823)
* perf: Use latest pickle protocol

* perf: pop flags from cached documents

This is also the right thing to do, things like `doc.flags.for_update`
shouldn't be "cached".
2024-12-18 10:18:04 +00:00
Ankush Menat
5e4f23720a
perf: Use raw SQL for fetching documents (#28789)
`get_doc` is single most used commands, directly and indirectly.
Currently there's QB overhead of building queries.

These queries are SO SIMPLE, I don't believe we need QB to keep these
maintainable or compatible with databases.

Microbenchmarks (first is simple flat document, second has many child tables):

```
bench_orm_bench_get_doc: Mean +- std dev: [before] 10.7 ms +- 0.2 ms -> [after] 7.24 ms +- 0.15 ms: 1.48x faster
bench_orm_bench_get_user: Mean +- std dev: [before] 16.3 ms +- 0.2 ms -> [after] 9.50 ms +- 0.14 ms: 1.72x faster
```
2024-12-16 13:27:07 +00:00
barredterra
beab110ce9 fix: clarify error message for child tables 2024-12-10 17:06:55 +01:00
Sumit Bhanushali
91d553c9cf
Merge pull request #28363 from frappe/expr-series
fix(NamingExpression): series should be separate for different format expressions instead of global
2024-12-09 12:13:28 +05:30
David Arnold
75377aaaf5
refactor(typing): type filters (#28218)
* chore(typing): type filters

* chore(typing): type filters for get_list et al

* fix: dashboard chart filter expression

* test: fix case with new-style right hand object to equality check

* chore: place new typed filter under typing verification

* chore: remove debug print statment

* chore: inverse logic of type guard

* fix: add float to filter value types

* chore: clarify value naming
2024-12-04 23:18:53 +00:00
Akhil Narang
84ef6ec677
refactor: fixup with ruff 0.8.1
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 13:18:04 +05:30
Sumit Bhanushali
e967b37c78 fix: workflow should also support queue_in_background
(cherry picked from commit 3d51e725c6bd89af4cd215a858ab25725b24c847)
2024-12-03 07:02:27 +00:00
Faris Ansari
f7c005dc09
Merge pull request #28629 from netchampfaris/autoincrement-renaming
fix: allow renaming autoincrement documents
2024-12-02 14:25:05 +05:30