Skip to content

Commit 8dbb304

Browse files
committed
log errors on import, fix error when group is not present, chunk data to avoid memory problems
1 parent baca49b commit 8dbb304

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ app.post('/webhooks/bundestagio/update', async (req, res) => {
6666
});
6767
console.log(`Updated: ${updated}`);
6868
} catch (error) {
69+
console.log(error);
6970
res.send({
7071
error,
7172
succeeded: false,

src/scripts/webhook.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export default async (data) => {
2828
await Promise.all(data.map(async (d) => {
2929
const period = parseInt(d.period, 10);
3030
const { type, countBefore, changedIds } = d.types.find(t => t.type === 'Gesetzgebung');
31-
const localCount = groups.find(c => c.period === period).types
32-
.find(ct => ct.type === type).count;
31+
const group = groups.find(c => c.period === period);
32+
const localCount = group ? group.types
33+
.find(ct => ct.type === type).count : 0;
3334
// Append Changed IDs
3435
update.concat(changedIds);
3536
// Compare Counts Remote & Local
@@ -51,6 +52,15 @@ export default async (data) => {
5152
});
5253
}
5354
}));
54-
// Update
55-
return importProcedures(update);
55+
56+
// Splitt in Chunks & Update
57+
const chunkSize = 100;
58+
let updateCount = 0;
59+
let i = 0;
60+
for (i = 0; i < update.length; i += chunkSize) {
61+
const part = update.slice(i, i + chunkSize);
62+
updateCount += await importProcedures(part); // eslint-disable-line no-await-in-loop
63+
}
64+
65+
return updateCount;
5666
};

0 commit comments

Comments
 (0)