question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selective sync ignores delta sync

See original GitHub issue

Describe the bug We are trying out the selective sync but the sync operations seem to be called from scratch on every page reload (like if delta sync was not taken into account).

When not using any selective sync and on DataStore.start(), on page refresh, sync operations were returning: {data: [] } because nothing had changed.

But, with the selective sync, when reloading the page, all sync operations are returning all the data again which is a huge performance drawback.

This issue was supposed to be solved by https://github.com/aws-amplify/amplify-js/pull/7200 But the problem persists anyway. To Reproduce The following configuration

const getClientId = async () => { 
const user = await Auth.currentAuthenticatedUser(); const userAttributes = await Auth.userAttributes(user); 
const clientIdAttribute = userAttributes.find((attribute) => attribute.getName() === ‘custom:clientId’); 
return !isNil(clientIdAttribute) && !isNil(clientIdAttribute.getValue()) ? clientIdAttribute.getValue() : null; 
}; 

DataStore.configure({ 
syncExpressions: [ 
    syncExpression(Address, async () => { 
    const clientId = await getClientId(); 
    return (t: ModelPredicate<Address>) => t!.clientId(‘eq’, clientId!); 
    }), 
  syncExpression(Contact, async () => { 
  const clientId = await getClientId(); 
  return (t: ModelPredicate<Contact>) => t!.clientId(‘eq’, clientId!); }); 
   }),
 ],
});

Refetch all data in the sync queries at each refresh, like nothing was synced. (The clientId is the same each time as the user stays logged in and just refreshing the page.) Expected behavior If nothing has changed in the database, the sync operations should be returning {data: [] }

What is Configured? I’m using the latest version of @aws-amplify/datastore

If applicable, please provide what is configured for Amplify CLI:

  • Which resources do you have configured?
    • If applicable, please provide your aws-exports file:
const awsmobile = {
 "aws_project_region": "eu-west-1",
 "aws_cognito_identity_pool_id": "eu-west-1:xxxx",
 "aws_cognito_region": "eu-west-1",
 "aws_user_pools_id": "eu-west-1_xxxxxx",
 "aws_user_pools_web_client_id": "xxxxx",
 "oauth": {
     "domain": "xxxxx-dev.auth.eu-west-1.amazoncognito.com",
     "scope": [
         "phone",
         "email",
         "openid",
         "profile",
         "aws.cognito.signin.user.admin"
     ],
     "redirectSignIn": "https://app.xxxxx.com/,https://dev.xxxxx.com/,https://test.xxxxx.com/,http://localhost:3000/,exp://127.0.0.1:19000/--/,xxxx://",
     "redirectSignOut": "https://app.xxxxx.com/,https://dev.xxxxx.com/,https://test.xxxxxx.com/,http://localhost:3000/,exp://127.0.0.1:19000/--/,xxx://",
     "responseType": "code"
 },
 "federationTarget": "COGNITO_USER_AND_IDENTITY_POOLS",
 "aws_content_delivery_bucket": "xxxxxx-xxxx-hostingbucket-dev",
 "aws_content_delivery_bucket_region": "eu-west-1",
 "aws_content_delivery_url": "https://xxxxx.cloudfront.net",
 "aws_user_files_s3_bucket": "xxxxx-dev",
 "aws_user_files_s3_bucket_region": "eu-west-1",
 "aws_appsync_graphqlEndpoint": "https://xxxxxxx.appsync-api.eu-west-1.amazonaws.com/graphql",
 "aws_appsync_region": "eu-west-1",
 "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
 "aws_cloud_logic_custom": [
     {
         "name": "xxxx",
         "endpoint": "https://xxxxx.execute-api.eu-west-1.amazonaws.com/dev",
         "region": "eu-west-1"
     }
 ],
 };
  • If applicable, please provide your manual configuration example:
   Amplify.configure({
...awsExports,
API: {
 graphql_endpoint: awsExports.aws_appsync_graphqlEndpoint,
 graphql_region: awsExports.aws_appsync_region,
 graphql_authenticationType: awsExports.aws_appsync_authenticationType,
 aws_appsync_graphqlEndpoint: awsExports.aws_appsync_graphqlEndpoint,
 aws_appsync_region: awsExports.aws_appsync_region,
 aws_appsync_authenticationType: awsExports.aws_appsync_authenticationType,

 graphql_headers: async () => {
   const session = await Auth.currentSession();
   return {
     Authorization: session.getIdToken().getJwtToken(),
   };
 },
 },
 });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
iartemievcommented, Feb 18, 2021

Your teammate SebS reached out to me on Discord and provided the requested files. I was able to reproduce and opened a PR in the CLI repo with a minor bug fix.

1reaction
TheMoumscommented, Feb 26, 2021

It is now working with the latest version of amplify cli.

Thanks a lot!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

UPN not syncing in delta sync (4253409) - Quest Support
There's an issue where DirSync is not changing the target UPN attribute to match the source UPN attribute on user objects unless ther ......
Read more >
Delta Sync - Valence documentation
Delta Sync With Cursors​​ Not every system uses a last modified timestamp to track changed records. Perhaps you're interacting with a message queue...
Read more >
selective sync and delta sync in the desktop client : r/NextCloud
Is there any progress on the implementation of selective sync and delta sync in the desktop client? Surely this must be a feature...
Read more >
DataStore - Syncing data to cloud - JavaScript - Amplify Docs
Selective sync works by applying predicates to the base and delta sync queries, ... Any subsequent expressions for the same model will be...
Read more >
Troubleshoot Azure AD Connect objects and attributes
Describes how to determine why an object is not syncing in Azure AD. ... During a delta import from AD, AADC requests all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found