refactor(model): simplify prefetch per szufisher's suggestion

- Remove fetch_if_empty check from prefetch phase
- Fetch ALL fields, let base_document.py handle fetch_if_empty
- Avoids DRY violation (same logic in two places)
- Efficiency difference is negligible
This commit is contained in:
Ayaan Ahmad 2026-01-17 21:29:48 +05:30
parent 6197b73d52
commit 614bb642ef

View file

@ -1179,11 +1179,9 @@ class Document(BaseDocument):
prefetch_map[doctype]["names"].add(docname)
# Collect fetch_from fields
# Collect fetch_from fields - fetch ALL, let base_document handle fetch_if_empty
for fetch_df in doc.meta.get_fields_to_fetch(df.fieldname):
if not fetch_df.get("fetch_if_empty") or (
fetch_df.get("fetch_if_empty") and not doc.get(fetch_df.fieldname)
):
if fetch_df.get("fetch_from"):
source_field = fetch_df.fetch_from.split(".")[-1]
prefetch_map[doctype]["fields"].add(source_field)