Skip to content

Commit 987891f

Browse files
committed
feat(dart): savePopularRecords
1 parent 8eedda0 commit 987891f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{> snippets/import}}
2+
3+
void savePopularRecords() async {
4+
{{> snippets/init}}
5+
6+
List<Map<String, dynamic>> records = [];
7+
8+
BrowseResponse? browseResponse;
9+
do {
10+
var browseParams = BrowseParamsObject(hitsPerPage: 1000, cursor: browseResponse?.cursor);
11+
browseResponse = await client.browse(
12+
indexName: "indexName", browseParams: browseParams
13+
);
14+
for (var hit in browseResponse.hits) {
15+
final isPopular = hit['nbFollowers'] > 1000;
16+
final updatedProduct = {
17+
...hit,
18+
'isPopular': isPopular,
19+
};
20+
records.add(updatedProduct);
21+
}
22+
} while (browseResponse.cursor != null);
23+
24+
var batchParams = BatchWriteParams(
25+
requests: records
26+
.map((record) => BatchRequest(
27+
action: Action.addObject,
28+
body: record,
29+
))
30+
.toList());
31+
await {{#dynamicSnippet}}batchChunks{{/dynamicSnippet}};
32+
}

0 commit comments

Comments
 (0)