Last active
May 1, 2020 07:09
-
-
Save devxpy/89ea7c2f0570a898c416d31e49f9cd26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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