feat: remove obsolete lineage view and refactor fetching to use all_docs#10787
feat: remove obsolete lineage view and refactor fetching to use all_docs#10787sh1vam31 wants to merge 17 commits intomedic:masterfrom
Conversation
|
Hi @witash, The ci-compile check failed due to a transient CI infrastructure issue, not a code problem. The shellcheck binary download from GitHub was rate-limited (HTTP 403) during the npm run lint-shell step: RequestError: Status code '403' and message 'rate limit exceeded' The ESLint and blank-link checks both passed successfully. This is unrelated to the code changes in this PR. Could you please re-run the failed job, or let me know if there's another way to trigger CI? I |
|
I consistenly get this error running the stub at webapp/tests/karma/ts/services/lineage-model-generator.service.spec.ts:339 may be the culprit? not containing 'x' becuase it was already present so was not fetched again? Or something similar. |
|
|
I tested the performance of this on a small db using There might be more difference if it was getting the lineage for batches of ids, instead of each id individually...but currently it does each id individually so it doesn't matter.
|
| Metric | Value |
|---|---|
| Count | 10000 |
| Min | 6.0 ms |
| Median (p50) | 11.0 ms |
| Mean | 12.6 ms |
| p90 | 18.3 ms |
| p95 | 19.2 ms |
| p99 | 21.1 ms |
| Max | 28.9 ms |
Total: 126.0s
This branch
| Metric | Value |
|---|---|
| Count | 10000 |
| Min | 5.3 ms |
| Median (p50) | 9.2 ms |
| Mean | 11.3 ms |
| p90 | 16.7 ms |
| p95 | 17.5 ms |
| p99 | 19.7 ms |
| Max | 32.0 ms |
Total: 113.0s
|
Hi @witash I’ve just pushed a new set of fixes to address the test regressions and linting errors identified in your review. Summary of changes: Lineage Unit Tests: Updated both the Webapp and Admin LineageModelGenerator tests to support the new allDocs-based hydration logic. This included embedding full parent chains in mock documents and correcting the Sinon stub assertions to match the new fetch sequence. Thanks for your guidance. |
Description
Fixes #10748
This PR removes the obsolete and resource-heavy docs_by_id_lineage map-reduce view from the medic-client design document and replaces the lineage-fetching logic with a more efficient two-step all_docs process.
The docs_by_id_lineage view was previously one of the largest views in the system, emitting every ancestor for every record. As identified in Issue #10748, this can be replaced by direct document retrieval since the child document already contains the necessary ancestor chain.This PR removes the obsolete and resource-heavy docs_by_id_lineage map-reduce view from the medic-client design document and replaces the lineage-fetching logic with a more efficient two-step all_docs process.
The docs_by_id_lineage view was previously one of the largest views in the system, emitting every ancestor for every record. As identified in Issue #10748, this can be replaced by direct document retrieval since the child document already contains the necessary ancestor chain.
Changes
Refactoring Fetch Logic
shared-libs/lineage: Updated fetchLineageById in hydration.js to first fetch the child document via DB.get() and then retrieve all ancestors using their IDs in a single DB.allDocs() call.
shared-libs/cht-datasource: Updated getLineageDocsById in lineage.ts to implement the same two-step fetch strategy for local data contexts.
Ancestor Resolution: Maintained accurate lineage depth and order by ensuring that if an ancestor is missing, it is correctly represented as null in the resulting array.
View Removal & Cleanup
ddocs/medic-db: Deleted the docs_by_id_lineage view definition.
webapp/tests: Removed the now-obsolete docs_by_id_lineage.spec.js unit test.
Test Updates
Updated mocks and unit tests in shared-libs/lineage, shared-libs/cht-datasource, admin, and webapp to match the new fetching pattern.
Updated API integration tests in server.spec.js to ensure the hydration endpoint remains fully functional without the view dependency.
Code review checklist
can_view_old_navigationpermission to see the old design. Test it has appropriate design for RTL languages.License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.