Skip to content

Conversation

@seadowg
Copy link
Member

@seadowg seadowg commented Oct 27, 2025

Closes #6843

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

To make things (hopefully) simpler to understand in the download code, I've introduced a new Type enum to ServerFormDetails that replaces the existing booleans for isNotOnDevice and isUpdated. This allows our download code to make optimizations based on the download scenario explicitly rather than having to infer it from several pieces of information.

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?

There should be no change in behaviour here - the only thing that should change is the performance of updating an entity list for a form that has many media files (and none have changed).

Do we need any specific form for testing your changes? If so, please attach one.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@seadowg seadowg changed the title Add type to ServerFormDetails Add type to ServerFormDetails Oct 27, 2025
@seadowg seadowg force-pushed the form-download-types branch 3 times, most recently from 95899e8 to b09632e Compare October 30, 2025 16:20
@seadowg seadowg changed the title Add type to ServerFormDetails Don't copy existing media files when updating media only Oct 30, 2025
}
}

public interface ServerFormsDetailsFetcher {
Copy link
Member Author

Choose a reason for hiding this comment

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

We could simplify this by converting to Kotlin, but I wanted to try and limit the change set here!

@seadowg seadowg marked this pull request as ready for review October 30, 2025 17:02
@seadowg seadowg requested a review from grzesiek2010 October 30, 2025 17:02
}
} else if (thisFormAlreadyDownloaded) {
if (listItem.hash == null) {
ServerFormDetails.Type.OnDevice
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm not sure about this. If existingForm == null so that we end up here in the else block, that means the form is not on the device. If hash is null we should rather assume it's a new one.

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't a change in behaviour right? Maybe I'm missing something, but this how it worked before, and it's also not something that should happen with a "well-behaved" server. It might not be quite right, but we'd need to carefully consider changing any of the behaviour here as it could break existing "badly behaved" servers.


if (existingFileHash.contentEquals(mediaFile.hash)) {
copyFileToDirectory(existingFile, tempMediaDir)
if (formToDownload.type != ServerFormDetails.Type.UpdatedMedia) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be or != Type.OnDevice?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only case we don't want to copy existing media files to the "sandbox" directory is when we're doing a media-only update as the existing media files are already where they need to be. In other update cases, the files will be needed for the new version's media directory.

There's potentially an additional optimization where we copy existing media files from their original version to the new version directory (and never to the sandbox directory), but we didn't need to do that to hit our benchmark targets here.

if (existingFile != null) {
val existingFileHash = existingFile.getMd5Hash()

if (existingFileHash.contentEquals(mediaFile.hash)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we update searchForExistingMediaFile to check the hash as well so that existingFile is null if the file exists but has been updated? That would simplify the structure here a little bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ach I thought we could for a sec, but we need to check here for the case where we download a file we think has a new hash, but it doesn't below here.

val type: Type
) : Serializable {

@Deprecated(message = "Use primary constructor instead")
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of it if it is only used in tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are 51 uses, so it'll be a real slog to change all at once and a lot of noise for the PR. I'd thought it made sense to just change incrementally.

@seadowg seadowg force-pushed the form-download-types branch from b09632e to f9db6d5 Compare November 26, 2025 13:37
@seadowg seadowg requested a review from grzesiek2010 November 26, 2025 14:36
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.

Reduce time taken to update form with entity list and many media files

2 participants