Selective sync ignores delta sync
See original GitHub issueDescribe 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:
- If applicable, please provide your
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:
- Created 3 years ago
- Comments:18 (10 by maintainers)
Top GitHub Comments
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.
It is now working with the latest version of amplify cli.
Thanks a lot!!