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

RN-400: Meditrak permissions based sync (app-side changes) #3995

Merged

Conversation

rohan-bes
Copy link
Collaborator

Issue RN-400:

Changes to meditrak-app to support permissions based synchronization. Much simpler changes here, refer to the other PR for the logic

@@ -16,7 +16,7 @@ const HomeToolbar = ({ onNavigateToSurveysMenu, onNavigateToTupaiaWebsite, style
textStyle={localStyles.buttonText}
/>
<BlueButton
title="SURVEY FACILITIES"
title="SURVEY"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@edmofro 2 months of refactors and now I'm finally able to make this change 😉

Copy link
Member

Choose a reason for hiding this comment

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

Bahahahaha 😂

@@ -28,7 +31,7 @@ const MEASURE_BATCH_IN_DATA = 'kilobytes';
const KILOBYTE = 1024; // bytes

const MIN_BATCH_RECORDS = 1;
const MAX_BATCH_RECORDS = 500;
const MAX_BATCH_RECORDS = 2000;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Based on the api_request_log, the majority of our syncs manage to hit this 500 max, so I bumped it to 2000. This also gets hit pretty easily on my local, but the app write speed is balanced with the query time more effeciently 👍

@@ -246,61 +250,50 @@ export class Synchroniser {
*/
async pushChanges(changesSyncJson) {
const startTime = new Date().getTime();
try {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed all the redundant try/catches. ESlint told me to

Copy link
Member

Choose a reason for hiding this comment

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

Yes thank you for this!

@@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.11.121</string>
<string>1.12.123</string>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Funny new app number here, it seems like we track the version just by the last number? But semver suggests we should bump the middle number for new features...

Copy link
Member

Choose a reason for hiding this comment

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

Yes it is funny! Have just updated the slab doc here to explain the reason, but to repost:

Don't reset or wrap patch number, instead ALWAYS just increment it by 1 with every release. This is because we use a shortcut where the patch number doubles as the android build number, which needs to increase monotonically.

Copy link
Member

@edmofro edmofro left a comment

Choose a reason for hiding this comment

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

Two very superficial suggestions, but both are non-blocking. Looking great :-)

const countriesSynced = this.database.getSetting(COUNTRIES_SYNCED);
const permissionGroupsSynced = this.database.getSetting(PERMISSION_GROUPS_SYNCED);
if (countriesSynced) {
// eslint-disable-next-line no-param-reassign
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there's much waste in creating a clone of the incoming parameter to avoid the eslint disabling (and discouraging the practice of the unsafe pattern)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah... you're right huh? I get a bit too cowboy with this pattern from time to time, will fix this 👍

Comment on lines 302 to 312
* Returns the number of changes left to pull
* @return {Promise} Resolves with the change count, or passes up any error thrown
*/
async getIncomingChangeCount(since, filters = {}) {
try {
const responseJson = await this.api.get(`${API_ENDPOINT}/count`, { since, ...filters });
if (responseJson.error && responseJson.error.length > 0) {
throw new Error(responseJson.error);
}
if (typeof responseJson.changeCount !== 'number') {
throw new Error('Unexpected response from server');
}
return responseJson.changeCount;
} catch (error) {
throw error; // Throw error up
async getIncomingChangeMetadata(since, filters = {}) {
const countriesSynced = this.database.getSetting(COUNTRIES_SYNCED);
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice somewhere around here to add a comment briefly describing the way sync is filtered by permissions, so the reader doesn't need to look into the server code to understand what's going on

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great point! Will do 😄

@rohan-bes rohan-bes force-pushed the rn-400-permissions-based-sync-p1 branch from adf82df to 2e35a56 Compare July 27, 2022 23:45
@rohan-bes rohan-bes force-pushed the rn-400-permissions-based-sync-p2 branch 2 times, most recently from 7d5888d to f81308c Compare July 28, 2022 23:31
@rohan-bes rohan-bes force-pushed the rn-400-permissions-based-sync-p1 branch from 5eac074 to a9979fe Compare July 29, 2022 01:53
- Track countries and permissions groups that are synced to the database
- Only fetch data for countries and permissions groups that the user has
access to or the device has already synced
- Added comment explaining why we track and pass through the countries/permission groups synced
- Stopped doing naughty param reassign business
@rohan-bes rohan-bes force-pushed the rn-400-permissions-based-sync-p2 branch from f81308c to e266ffb Compare July 29, 2022 01:54
@rohan-bes rohan-bes merged commit 05aa2e9 into rn-400-permissions-based-sync-p1 Aug 2, 2022
@rohan-bes rohan-bes deleted the rn-400-permissions-based-sync-p2 branch August 2, 2022 00:10
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.

2 participants