@@ -47,6 +47,7 @@ async def resolve_link(
4747 use_search : bool = True ,
4848 strict : bool = False ,
4949 source_path : Optional [str ] = None ,
50+ load_relations : bool = True ,
5051 ) -> Optional [Entity ]:
5152 """Resolve a markdown link to a permalink.
5253
@@ -56,6 +57,7 @@ async def resolve_link(
5657 strict: If True, only exact matches are allowed (no fuzzy search fallback)
5758 source_path: Optional path of the source file containing the link.
5859 Used to prefer notes closer to the source (context-aware resolution).
60+ load_relations: When False, skip eager loading and return a lightweight entity row.
5961 """
6062 logger .trace (f"Resolving link: { link_text } (source: { source_path } )" )
6163
@@ -70,7 +72,10 @@ async def resolve_link(
7072 # UUIDs also match the stored external_id values.
7173 try :
7274 canonical_id = str (uuid_mod .UUID (clean_text ))
73- entity = await self .entity_repository .get_by_external_id (canonical_id )
75+ entity = await self .entity_repository .get_by_external_id (
76+ canonical_id ,
77+ load_relations = load_relations ,
78+ )
7479 if entity :
7580 logger .debug (f"Found entity by external_id: { entity .permalink } " )
7681 return entity
@@ -98,6 +103,7 @@ async def resolve_link(
98103 strict = strict ,
99104 source_path = None ,
100105 project_permalink = project .permalink ,
106+ load_relations = load_relations ,
101107 )
102108
103109 current_project_permalink = await self ._get_current_project_permalink ()
@@ -109,6 +115,7 @@ async def resolve_link(
109115 strict = strict ,
110116 source_path = source_path ,
111117 project_permalink = current_project_permalink ,
118+ load_relations = load_relations ,
112119 )
113120 if resolved :
114121 return resolved
@@ -136,6 +143,7 @@ async def resolve_link(
136143 strict = strict ,
137144 source_path = None ,
138145 project_permalink = project .permalink ,
146+ load_relations = load_relations ,
139147 )
140148
141149 def _normalize_link_text (self , link_text : str ) -> Tuple [str , Optional [str ]]:
@@ -176,6 +184,7 @@ async def _resolve_in_project(
176184 strict : bool ,
177185 source_path : Optional [str ],
178186 project_permalink : Optional [str ],
187+ load_relations : bool ,
179188 ) -> Optional [Entity ]:
180189 """Resolve a link within a specific project scope."""
181190 clean_text = link_text
@@ -223,12 +232,18 @@ async def _resolve_in_project(
223232 # Try with .md extension
224233 if not relative_path .endswith (".md" ):
225234 relative_path_md = f"{ relative_path } .md"
226- entity = await entity_repository .get_by_file_path (relative_path_md )
235+ entity = await entity_repository .get_by_file_path (
236+ relative_path_md ,
237+ load_relations = load_relations ,
238+ )
227239 if entity :
228240 return entity
229241
230242 # Try as-is (already has extension or is a permalink)
231- entity = await entity_repository .get_by_file_path (relative_path )
243+ entity = await entity_repository .get_by_file_path (
244+ relative_path ,
245+ load_relations = load_relations ,
246+ )
232247 if entity :
233248 return entity
234249
@@ -242,12 +257,18 @@ async def _resolve_in_project(
242257
243258 # Check permalink match
244259 for candidate_permalink in permalink_candidates :
245- permalink_entity = await entity_repository .get_by_permalink (candidate_permalink )
260+ permalink_entity = await entity_repository .get_by_permalink (
261+ candidate_permalink ,
262+ load_relations = load_relations ,
263+ )
246264 if permalink_entity and permalink_entity .id not in [c .id for c in candidates ]:
247265 candidates .append (permalink_entity )
248266
249267 # Check title matches
250- title_entities = await entity_repository .get_by_title (clean_text )
268+ title_entities = await entity_repository .get_by_title (
269+ clean_text ,
270+ load_relations = load_relations ,
271+ )
251272 for entity in title_entities :
252273 # Avoid duplicates (permalink match might also be in title matches)
253274 if entity .id not in [c .id for c in candidates ]:
@@ -263,29 +284,41 @@ async def _resolve_in_project(
263284 # Standard resolution (no source context): permalink first, then title
264285 # 1. Try exact permalink match first (most efficient)
265286 for candidate_permalink in permalink_candidates :
266- entity = await entity_repository .get_by_permalink (candidate_permalink )
287+ entity = await entity_repository .get_by_permalink (
288+ candidate_permalink ,
289+ load_relations = load_relations ,
290+ )
267291 if entity :
268292 logger .debug (f"Found exact permalink match: { entity .permalink } " )
269293 return entity
270294
271295 # 2. Try exact title match
272- found = await entity_repository .get_by_title (clean_text )
296+ found = await entity_repository .get_by_title (
297+ clean_text ,
298+ load_relations = load_relations ,
299+ )
273300 if found :
274301 # Return first match (shortest path) if no source context
275302 entity = found [0 ]
276303 logger .debug (f"Found title match: { entity .title } " )
277304 return entity
278305
279306 # 3. Try file path
280- found_path = await entity_repository .get_by_file_path (clean_text )
307+ found_path = await entity_repository .get_by_file_path (
308+ clean_text ,
309+ load_relations = load_relations ,
310+ )
281311 if found_path :
282312 logger .debug (f"Found entity with path: { found_path .file_path } " )
283313 return found_path
284314
285315 # 4. Try file path with .md extension if not already present
286316 if not clean_text .endswith (".md" ) and "/" in clean_text :
287317 file_path_with_md = f"{ clean_text } .md"
288- found_path_md = await entity_repository .get_by_file_path (file_path_with_md )
318+ found_path_md = await entity_repository .get_by_file_path (
319+ file_path_with_md ,
320+ load_relations = load_relations ,
321+ )
289322 if found_path_md :
290323 logger .debug (f"Found entity with path (with .md): { found_path_md .file_path } " )
291324 return found_path_md
@@ -309,7 +342,10 @@ async def _resolve_in_project(
309342 f"Selected best match from { len (results )} results: { best_match .permalink } "
310343 )
311344 if best_match .permalink :
312- return await entity_repository .get_by_permalink (best_match .permalink )
345+ return await entity_repository .get_by_permalink (
346+ best_match .permalink ,
347+ load_relations = load_relations ,
348+ )
313349
314350 # if we couldn't find anything then return None
315351 return None
0 commit comments