Skip to content

Conversation

@dianabarsan
Copy link
Member

@dianabarsan dianabarsan commented Oct 9, 2025

Description

Updates device_by_user reduce function to be built-in _last.

Performance results, querying database with 400.000 telemetry documents:

branch time improvement
master 1144s
proposed 33s 34 times faster

Unfortunately, the new built-in reduce _last was added in CouchDb 3.5, which means that upgrades from older versions of CHT, that use CouchDb 3.4 will fail.

closes #10298

Code review checklist

  • UI/UX backwards compatible: Test it works for the new design (enabled by default). And test it works in the old design, enable can_view_old_navigation permission to see the old design. Test it has appropriate design for RTL languages.
  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

Signed-off-by: Diana Barsan <[email protected]>
@dianabarsan dianabarsan requested a review from sugat009 October 10, 2025 06:47
@dianabarsan
Copy link
Member Author

For the record, this is the error that we expect when trying to upgrade from a version that does not use CouchDb 3.5 (any cht < 4.21):

2025-10-09 13:08:52 �[32mINFO�[39m: Saving ddocs for medic-users-meta 
2025-10-09 13:08:52 �[31mERROR�[39m: Error thrown while installing: Error: Error while saving docs: saving _design/:staged:users-meta failed with invalid_design_doc
    at Object.module.exports.saveDocs (/api/src/db.js:164:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.saveStagedDdocs (/api/src/services/setup/utils.js:258:5)
    at async Object.stage (/api/src/services/setup/upgrade-steps.js:92:3)
    at async safeInstall (/api/src/services/setup/upgrade.js:40:5) {
  [stack]: 'Error: Error while saving docs: saving _design/:staged:users-meta failed with invalid_design_doc\n' +
    '    at Object.module.exports.saveDocs (/api/src/db.js:164:11)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
    '    at async Object.saveStagedDdocs (/api/src/services/setup/utils.js:258:5)\n' +
    '    at async Object.stage (/api/src/services/setup/upgrade-steps.js:92:3)\n' +
    '    at async safeInstall (/api/src/services/setup/upgrade.js:40:5)',
  [message]: 'Error while saving docs: saving _design/:staged:users-meta failed with invalid_design_doc'
} 

This error would occur immediately after hitting the upgrade/stage button, while API tries to start indexing the new version's views.

@sugat009
Copy link
Member

@dianabarsan what is the workaround for this?

@dianabarsan
Copy link
Member Author

That deployments update to v 4.21 before the version with this fix.

@dianabarsan dianabarsan changed the title fix(#10298): update device_by_user to use built-in reduce fix(#10298): update device_by_user to use built-in reduce [DO NOT MERGE] Oct 15, 2025
@dianabarsan dianabarsan marked this pull request as draft October 15, 2025 12:37
@github-actions
Copy link

This PR is now marked "stale" after 30 days without activity. It will be closed automatically in 10 days unless you add a comment, push new changes or remove the "stale" label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More easily allow user-devices API to be called

3 participants