Skip to content

Submissions.newVersion(): reduce repeated data#1606

Merged
alxndrsn merged 4 commits intogetodk:masterfrom
alxndrsn:joingo-unjoined-2
Sep 6, 2025
Merged

Submissions.newVersion(): reduce repeated data#1606
alxndrsn merged 4 commits intogetodk:masterfrom
alxndrsn:joingo-unjoined-2

Conversation

@alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Sep 5, 2025

  1. only return data from the db which is not already available
  2. reduce nested queries
  3. only update the current row in submission_defs
  4. add extra JOIN on submission_defs to return root row's userAgent (necessary to achieve 4)

Neater rewrite of #1544
Related: getodk/central#1170

What has been done to verify that this works as intended?

CI!

Why is this the best possible solution? Were any other approaches considered?

Discussion at #1544; this is a neater rewrite of that, specifically tackling the Submissions.createVersion() function, where the xml field was previously passed to the database and then returned.

This PR could be changed to return query formatting to match the original more closely. To me this makes understanding the query significantly harder.

Potential follow-ups:

  • Look at refactoring Submissions.createNew(). It looks like the query can be inverted and simplified.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Should not affect users.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

No.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

1. only return data from the db which is not already available
2. reduce nested queries
3. only update the `current` row in submission_defs
4. add extra JOIN on submission_defs to return root row's userAgent (necessary to achieve 4)
`)
.then(({ submissionDefId, submissionDefCreatedAt, ...submissionData }) => // TODO/HACK: reassembling this from bits and bobs.
new Submission({ id: deprecated.submissionId, ...submissionData }, {
currentVersion: new Submission.Def({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we disable these eslint rules for the block of code instead of each line?

/* eslint-disable key-spacing, no-multi-spaces */
....
....
/* eslint-enable key-spacing, no-multi-spaces */

Copy link
Contributor

@sadiqkhoja sadiqkhoja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except for one comment, rest looks good to me

Copy link
Contributor

@brontolosone brontolosone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And so much more readable! To me at least.

@alxndrsn alxndrsn merged commit 85e25af into getodk:master Sep 6, 2025
6 checks passed
@alxndrsn alxndrsn deleted the joingo-unjoined-2 branch September 6, 2025 13:38
alxndrsn pushed a commit to alxndrsn/odk-central-backend that referenced this pull request Sep 8, 2025
alxndrsn added a commit that referenced this pull request Oct 15, 2025
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.

3 participants