Skip to content

Instantly share code, notes, and snippets.

@devxpy
Last active May 1, 2020 07:09
Show Gist options
  • Save devxpy/89ea7c2f0570a898c416d31e49f9cd26 to your computer and use it in GitHub Desktop.
Save devxpy/89ea7c2f0570a898c416d31e49f9cd26 to your computer and use it in GitHub Desktop.
var start = DateTime.now()
var db = await appSync.getCacheDatabase();
var pages = appSync.paginate(
...,
priority: CachePriority.cache, // Try cache first, then network
cache: db,
);
// get records between this range
var dateRange = [
DateTime.now().subtract(Duration(days: 7)),
DateTime.now().subtract(Duration(days: 3)),
];
// convert to timestamps
var dateRangeMs = dateRange.map((x) => x.millisecondsSinceEpoch).toList();
var results = pages
// Dart's version of FlatMap. (Combines records from pages into a single list)
.expand((x) {
return x['listLessons']['items'];
})
// filter by 'updatedAt'
.where((x) {
return x['updatedAt'] != null &&
dateRangeMs[0] < x['updatedAt'] &&
x['updatedAt'] < dateRangeMs[1];
})
.toList();
var end = DateTime.now()
print('Time taken: ${end.difference(now)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment