seitime-frappe/frappe/model
Ayaan Ahmad 3f86d478e8 perf(validation): optimize link validation with bulk pre-fetching
Implements a _prefetch_link_values method that bulk-fetches all link values
before validation, eliminating N+1 queries when saving documents with many
child rows containing Link/Dynamic Link fields.

Performance Impact:
- 50 child rows: 51 queries → 3 queries (94% reduction)
- 500 child rows: 501 queries → 3 queries (99.4% reduction)

Implementation:
- Uses instance-level cache (garbage collected after validation)
- Sentinel pattern to distinguish cache miss from cached-None
- DB-conditional case handling (MariaDB vs Postgres)
- Chunking at 1000 items for safety
- Backward compatible via **kwargs

Edge Cases Handled:
- Empty name lists (skip query)
- Invalid docname types (preserves existing assertions)
- Virtual doctypes (individual fetch)
- Single doctypes (special handling)
- Dynamic links with doctype changes (cache miss fallback)

Closes #35794
2026-01-12 20:23:54 +05:30
..
utils fix(model): fix postgres compatibility in update_user_settings 2025-12-24 11:33:42 +07:00
__init__.py feat: format IBANs in Data field 2025-08-26 23:41:00 +02:00
base_document.py perf(validation): optimize link validation with bulk pre-fetching 2026-01-12 20:23:54 +05:30
create_new.py fix: remove default value from time field (#33515) 2025-08-04 12:59:25 +05:30
db_query.py feat: implement field masking for query builder (#35230) 2025-12-16 12:08:13 +05:30
delete_doc.py chore: add correct docs url 2025-12-30 16:43:34 +05:30
docfield.py chore!: dead code (#19551) 2023-01-10 18:53:08 +05:30
docstatus.py chore: fix typo in new DocStatus constant 2025-03-05 08:29:47 +05:30
document.py perf(validation): optimize link validation with bulk pre-fetching 2026-01-12 20:23:54 +05:30
dynamic_links.py fix(dynamic_links): skip virtual docfields in dynamic link map 2025-09-25 16:55:18 +05:30
mapper.py chore: Revert document read only mode (#32102) 2025-04-12 18:27:16 +05:30
meta.py fix: specify valid rights for share query 2026-01-09 12:44:48 +05:30
naming.py fix(document naming): customer parser should be checked before anything else (#35586) 2026-01-05 13:44:32 +05:30
qb_query.py fix(with_comment_count): handle string values 2025-12-18 18:11:02 +05:30
rename_doc.py chore: remove unused import 2025-10-14 12:02:36 +05:30
sync.py chore: clean desktop icon controller 2025-12-18 14:20:00 +05:30
trace.py feat: global frappe.in_test flag (#32960) 2025-06-17 19:19:31 +05:30
virtual_doctype.py refactor: migrate virtual doctypes to new API 2024-03-11 18:25:05 +05:30
workflow.py feat: Support dynamic expressions in workflow update_value field (#34354) 2025-12-30 15:58:43 +05:30