Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Unsynced Time Limit to be set in hours #2744

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

avazirna
Copy link
Contributor

@avazirna avazirna commented Mar 1, 2024

Summary

Currently, the minimum frequency for CommCare to warn users that a sync is needed is daily, this PR allows setting time limits shorter than that. The property Unsynced Time Limit is expressed in days, so this change makes it possible to pass down a decimal number resulting in frequencies lower than 24 hours, when the value is lower than 1.

Ticket: https://dimagi.atlassian.net/browse/SC-3223

Safety Assurance

  • I have confidence that this PR will not introduce a regression for the reasons below

Automated test coverage

Unit tests don't cover this logic. I was tempted to add some, but this code lives in a private method so I would need to broaden the scope of the test.

@avazirna
Copy link
Contributor Author

avazirna commented Mar 1, 2024

@damagatchi retest this please

OrangeAndGreen
OrangeAndGreen previously approved these changes Mar 1, 2024
Copy link
Contributor

@OrangeAndGreen OrangeAndGreen left a comment

Choose a reason for hiding this comment

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

The math looks good. Nice that the inverted days_ago variable goes away.

@@ -152,12 +152,13 @@ private static boolean unsentFormNumberLimitExceeded(int numUnsentForms) {

private static boolean unsentFormTimeLimitExceeded(long lastSyncTime) {
SharedPreferences prefs = CommCareApplication.instance().getCurrentApp().getAppPreferences();
int unsentFormTimeLimit = Integer.parseInt(prefs.getString(UNSENT_FORM_TIME_KEY, "5"));
double unsentFormTimeLimitInDays = Double.parseDouble(prefs.getString(UNSENT_FORM_TIME_KEY, "5"));
int unsentFormTimeLimitInMinutes = (int)(unsentFormTimeLimitInDays * 24 * 60);
Copy link

Choose a reason for hiding this comment

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

How about converting this to seconds instead of minutes for even better precision?

Copy link

Choose a reason for hiding this comment

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

or miliseconds?
that way you avoid any conversion in the comparison later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I battled with the same question myself and ended up settling with minutes.

This makes it possible to set limits shorter than a day. The property
Unsynced Time Limit is expressed in days, a decimal number will
result in frequencies lower than 24 hours.
@avazirna avazirna force-pushed the allow-unsynced-time-limit-to-hours branch 2 times, most recently from c851dfc to efd46d6 Compare March 4, 2024 11:31
@avazirna avazirna force-pushed the allow-unsynced-time-limit-to-hours branch from efd46d6 to 0e39881 Compare March 4, 2024 12:04

return minutesSinceLastSync > unsentFormTimeLimitInMinutes;
return msecsSinceLastSync > unsentFormTimeLimitInMsecs;
Copy link

Choose a reason for hiding this comment

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

Nice!

Copy link

@mkangia mkangia left a comment

Choose a reason for hiding this comment

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

thanks @avazirna , I will leave the review to mobile team.

@avazirna avazirna added this to the 2.54 milestone Apr 9, 2024
@avazirna avazirna merged commit 594b224 into master Apr 17, 2024
4 of 6 checks passed
@avazirna avazirna deleted the allow-unsynced-time-limit-to-hours branch April 17, 2024 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants