Make output more deterministic (#13)
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 28 Sep 2020 12:55:40 +0000 (14:55 +0200)
committerGitHub <noreply@github.com>
Mon, 28 Sep 2020 12:55:40 +0000 (14:55 +0200)
Depending on the speed of the getRows() call the keys within the resulting
object might be ordered differently in between runs. Synchronously set the
values tp ensure a deterministic result.

src/manager.ts

index fe2c79868561454d855d13a7ac714301964277de..533c7e404451d753f2049750fcb6e8107c7880b6 100644 (file)
@@ -184,17 +184,24 @@ export class Manager {
       meta,
     };
 
-    await Promise.all(
+    const entries = await Promise.all(
       blacklists.map(
-        async (blacklist: Blacklist): Promise<void> => {
-          data[blacklist.type] = await blacklist.getRows(
-            new Date(start).getTime(),
-            new Date(end).getTime(),
-          );
+        async (blacklist: Blacklist): Promise<any> => {
+          return {
+            blacklist,
+            rows: blacklist.getRows(
+              new Date(start).getTime(),
+              new Date(end).getTime(),
+            )
+          };
         },
       ),
     );
 
+    entries.forEach(entry => {
+      data[entry.blacklist.type] = entry.rows
+    });
+
     const directory = path.dirname(filename);
     if (!(await fsExists(directory))) {
       await fsMkdir(directory);