ZhYQ1 opened a new pull request, #428:
URL: https://github.com/apache/hugegraph-ai/pull/428

   ## Summary
   
   `DocumentEngine._ingest()` and `DocumentsTasks.confirm()` loaded every bound 
object with `repo.get()` only to decide whether it should count as applied for 
link assertion, and then `_write_object()` loaded the same row again. This 
drops the pre-check read: `applied_ids` is derived from the write outcome, so 
each bound object is read once instead of twice.
   
   ## Background
   
   The bind+apply loop did:
   
   ```python
   current = await self.sc.repo.get(session, bound.object_type, 
bound.object_id)  # pre-check
   if current is not None:
       applied_ids.add((bound.object_type, bound.object_id))
   outcome_kind = await self._write_object(session, bound, ...)  # loads the 
same row again
   ```
   
   `_write_object()` already loads the current row to build its diff/merge 
path, so the pre-check is a pure duplicate round-trip per bound object, on 
every ingest and every task confirm. This is separate from the batched link 
expansion in #101, which only covered list queries.
   
   ## Changes
   
   - `documents/engine.py` — drop the pre-check `repo.get` in `_ingest`; 
`applied_ids` now comes from the outcome (`inserted` / `updated` / `noop` leave 
a committed object, only `candidate` does not). `outcome.references` is merged 
as before.
   - `documents/tasks.py` — same change in the confirm loop.
   - `tests/test_documents_ingest.py` — counts `repo.get` during an ingest, 
asserts one load per object.
   - `tests/test_documents_tasks.py` — an existing note writes back as `noop`, 
still gets its edge asserted (not parked as `ENDPOINT_NOT_COMMITTED`), and is 
loaded once.
   
   ## Query count
   
   For a run writing N bound objects: 2N reads (pre-check + `_write_object`) → 
N reads.
   
   ## Behavior
   
   No public API change. `noop` still counts as applied, so the idempotent link 
re-assert on reruns is preserved; `candidate` stays excluded (it only occurs 
for a missing object, so the derivation is equivalent).
   
   ## Test plan
   
   ```bash
   cd ontogeny
   ruff check server/ontogeny/documents/engine.py 
server/ontogeny/documents/tasks.py tests/test_documents_ingest.py 
tests/test_documents_tasks.py
   ruff format --check server/ontogeny/documents/engine.py 
server/ontogeny/documents/tasks.py tests/test_documents_ingest.py 
tests/test_documents_tasks.py
   pytest tests/test_documents_ingest.py tests/test_documents_tasks.py -q
   ```
   
   Result: new tests pass, 39 passed across the two modules, ruff clean.
   
   ## Notes
   
   - Baseline: `perf/query-links-batch @215f248`.
   - Deletion/retraction coverage stays in the existing tests 
(`test_document_removal_retracts_links_and_archives`, 
`test_rerun_is_idempotent_and_uses_packet_cache`).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to