Commit graph

276 commits

Author SHA1 Message Date
Sagar Vora
18dde69ab0 perf: dont serialize caches 2025-06-21 20:54:11 +05:30
Sagar Vora
d9fc9f21f9 perf: faster meta serialisation 2025-06-21 20:12:39 +05:30
Ankush Menat
e4bc7f361b
Revert: DocRef (#32866)
- Hardly used anywhere
- Too many hardcoded `__value__` calls without which it's not usable.
- Another type to worry about
2025-06-10 05:20:56 +00:00
Ankush Menat
7d7d77d762
perf: misc small cruft (#32778)
* perf: cache docstatus check for invalid links

* perf: avoid querying if doctype is single

* perf: cache is_single
2025-06-04 19:18:19 +05:30
Sagar Vora
beeeed4160 revert: meta signature 2025-04-12 18:29:25 +05:30
Sagar Vora
7421ffa79a feat: use cached_property without locks on all supported Python versions 2025-04-11 13:21:27 +05:30
Sagar Vora
628ddfd494 perf: remove repeated calls to get_permitted_fieldnames 2025-03-16 23:39:46 +05:30
Sagar Vora
32ff002c32 fix: revert valid columns cache
it is used only once when initialising doc
2025-03-16 01:10:29 +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
26b5d8de15 perf: better _table_fieldnames cache 2025-02-24 17:41:00 +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
Sandeep Kakde
165968714d
fix: update cache key for table_columns to new format (#31179) 2025-02-07 17:19:02 +05:30
Ankush Menat
8eafe67805 feat: share table size heuristic with meta 2025-02-03 09:29:31 +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
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
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
David Arnold
3c1392c8fd
fix: meta signature (#28526)
* fix: meta

* fix: test case

save is required:

1. Fetch values
```python
	def get_invalid_links(self, is_submittable=False):
		"""Return list of invalid links and also update fetch values if not set."""
		...
```

2. Is triggered by
```python

	def _validate_links(self):
		if self.flags.ignore_links or self._action == "cancel":
			return
        ...
```

3. Which is triggered by either `_save` or `insert`

----

`reload` does not trigger link fetch
```python
	def reload(self) -> "Self":
		"""Reload document from database"""
		return self.load_from_db()
```

Neither does the new calling path which does not excempt Document
from caching when initializing meta.

It can be proven that this revert would be an alternative fix. But this
seems design by accident and there's no preceivable reason to excempt
Document args from being cached normally.

diff --git a/frappe/model/meta.py b/frappe/model/meta.py
index c4321f0128..87452c812c 100644
--- a/frappe/model/meta.py
+++ b/frappe/model/meta.py
@@ -70,11 +70,10 @@ def get_meta(doctype: str | dict | DocRef, cached=True) -> "_Meta":
 	Returns:
 	    Meta object for the given doctype.
 	"""
-	if cached and (
-		doctype_name := getattr(doctype, "doctype", doctype)
-		if not isinstance(doctype, dict)
-		else doctype.get("doctype")
-	):
+	if cached and not isinstance(doctype, Document):
+		doctype_name = (
+			getattr(doctype, "doctype", doctype) if not isinstance(doctype, dict) else doctype.get("doctype")
+		)
 		if meta := frappe.cache.hget("doctype_meta", doctype_name):
 			return meta

Therefore, we comply the test.
2024-11-20 04:17:38 +00:00
David Arnold
15d122025f
feat: get_meta can derive meta from dict (#28525) 2024-11-20 01:36:04 +00:00
David Arnold
d5fd8d7c20
chore(docref): fix circular imports (#28282) 2024-10-24 22:31:12 +02:00
David Arnold
7348572af8
feat: docref identifier / proxy (#27973)
* feat: add DocRef

* feat: Add comprehensive test cases for DocRef functionality

* chore(db): add field type hints

* fix: ensure document stringer fulfills the DocRef contract
2024-10-19 09:40:26 +05:30
David Arnold
5d3697500e
refactor: improve maintainability with a simple dispatcher (#27975)
* refactor: improve maintainability with a simple dispatcher

* refactor: improve maintainability with a init dispatcher on Document

* refactor: improve maintainability with an init dispatcher on meta
2024-10-06 16:56:40 +00:00
David
d05f70f9ba
fix: return correct types for owner and modified_by 2024-10-03 23:25:11 +02:00
David
2de43f7797
feat: improve placement for custom field sections and columns 2024-09-26 12:54:30 +02:00
Raffael Meyer
b91cacdd18
feat!: enhance Language to become more of a Locale (#27178) 2024-09-21 16:02:58 +02:00
marination
a893341f95 fix: get_valid_fields excludes show_on_timeline, breaking migrations
Co-authored-by: Gavin <gavin.dsouza@switchup.de>
2024-09-02 17:27:50 +02:00
Gavin D'souza
074da5c553
fix: Separate meta.get_valid_fields from *columns 2024-08-28 18:12:42 +02:00
Gavin D'souza
151de897f1
fix: Use doc.get to safely check for attr
This bypasses the bungle during site creations when meta isn't present in
the database yet
2024-08-28 11:59:25 +02:00
Gavin D'souza
12e3cee4a6
fix!: Skip virtual fields in meta.get_valid_columns 2024-08-28 11:42:43 +02:00
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
Corentin Flr
f8ff2308e2
Merge branch 'frappe:develop' into fix-fieldlevel-access-to-shared-document-list 2024-01-15 01:32:51 +01:00
Ankush Menat
1f6201b4af feat: lazy global translated strings 2024-01-10 21:28:01 +05:30
Ankush Menat
d09df92497 fix(DX): Type annotations for Meta
`frappe.get_meta` returns which is 90% `DocType` + 10% `Meta` specific
stuff, this hack just allows us to mix both for autocompletions.
2024-01-10 15:58:03 +05:30
Corentin Flr
d7026b8a26
fix(meta)!: Allow level 0 fields when a doc has been shared with user 2023-12-21 14:40:44 +01:00
Ankush Menat
0fd6f5eed7
Merge pull request #23827 from frappe/api-docs
docs: add Python API missing docstrings / type hints
2023-12-21 12:13:05 +05:30
Ankush Menat
5ecacd0cd7
Merge pull request #23865 from ankush/no_virtual_select_star
fix: skip virtual fields in perm level checks during DB Query
2023-12-20 12:15:48 +05:30
Ankush Menat
5deabdde21 fix: skip virtual fields in perm level checks during DB Query
DB Query can't access virtual fields so it should ignore all virtual
fields.
2023-12-20 12:00:08 +05:30
Hussain Nagaria
8d2137c265 docs: consistent doc strings 2023-12-18 18:27:39 +05:30
marination
d4129721ce fix: Treat Document Links entries as all non-std fields
- Since the field name is specified use it as a non standard field because it is hard to determine which field is standard. It is often wrong to assume the first entry has the statndard field
2023-11-24 16:39:50 +01:00
Deepesh Garg
b3742b45a8
Merge pull request #22104 from GursheenK/doc-comparator
feat: audit trail
2023-09-13 14:04:15 +05:30
Gursheen Anand
177955a12f fix: check label for fields 2023-09-11 11:06:01 +05:30
Gursheen Anand
0d80ffc988 fix: return df label only when not none 2023-08-18 11:01:55 +05:30
Ankush Menat
c7847395da
fix: remove thread-unsafe class attributes (#22097)
The problem is same as mutable defaults. Container type class attributes
are mutable and shared between all objects.

```python
class CLS:
    attr = {}
    ...

a = CLS()
b = CLS()

a.attr is b.attr  # => True
```
2023-08-17 20:11:20 +05:30
barredterra
88c8baa9ee refactor: for append to extend, merge list extend
Replace a for append loop with list extend.
Create the list with values instead of creating
an empty list and extending it with another list.
2023-08-09 13:25:39 +02:00