Skip to content

Commit 6caa8ec

Browse files
committed
[BUG] Airtable triggers are getting OOM
1 parent ee00be3 commit 6caa8ec

File tree

6 files changed

+74
-51
lines changed

6 files changed

+74
-51
lines changed

components/airtable_oauth/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/airtable_oauth",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "Pipedream Airtable (OAuth) Components",
55
"main": "airtable_oauth.app.mjs",
66
"keywords": [

components/airtable_oauth/sources/common/common.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ export default {
4242
const formattedTimestamp = new Date(timestampMillis).toISOString();
4343
this._setLastTimestamp(formattedTimestamp);
4444
},
45+
getListRecordsParams(params) {
46+
return {
47+
filterByFormula: `LAST_MODIFIED_TIME() > "${this._getLastTimestamp()}"`,
48+
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
49+
...params,
50+
};
51+
},
4552
},
4653
};

components/airtable_oauth/sources/new-modified-or-deleted-records/new-modified-or-deleted-records.mjs

+39-30
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: "New, Modified or Deleted Records",
77
description: "Emit new event each time a record is added, updated, or deleted in an Airtable table. Supports tables up to 10,000 records",
88
key: "airtable_oauth-new-modified-or-deleted-records",
9-
version: "0.0.8",
9+
version: "0.0.9",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {
@@ -53,38 +53,46 @@ export default {
5353
const prevAllRecordIds = this._getPrevAllRecordIds();
5454

5555
const lastTimestamp = this._getLastTimestamp();
56-
const params = {
57-
filterByFormula: `LAST_MODIFIED_TIME() > "${lastTimestamp}"`,
58-
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
59-
};
56+
const params = this.getListRecordsParams();
6057

6158
const records = await this.airtable.listRecords({
6259
baseId,
6360
tableId,
6461
params,
6562
});
6663

67-
let allRecordIds = [],
68-
newRecordsCount = 0,
64+
let newRecordsCount = 0,
6965
modifiedRecordsCount = 0,
7066
deletedRecordsCount = 0;
7167

7268
if (records) {
7369
for (const record of records) {
74-
if (!lastTimestamp || moment(record.createdTime) > moment(lastTimestamp)) {
75-
record.type = "new_record";
70+
if (!lastTimestamp || moment(record.createdTime) > moment(lastTimestamp)) {;
71+
this.$emit({
72+
...record,
73+
type: "new_record",
74+
metadata,
75+
}, {
76+
id: record.id,
77+
summary: `New record: ${record.id}`,
78+
ts: moment(record.createdTime).valueOf(),
79+
});
7680
newRecordsCount++;
81+
7782
} else {
78-
record.type = "record_modified";
83+
const ts = Date.now();
84+
const id = `${record.id}-${ts}`;
85+
this.$emit({
86+
...record,
87+
type: "record_modified",
88+
metadata,
89+
}, {
90+
id,
91+
summary: `Record modified: ${record.id}`,
92+
ts,
93+
});
7994
modifiedRecordsCount++;
8095
}
81-
82-
record.metadata = metadata;
83-
84-
this.$emit(record, {
85-
summary: `${record.type}: ${JSON.stringify(record.fields)}`,
86-
id: record.id,
87-
});
8896
}
8997
}
9098

@@ -95,26 +103,27 @@ export default {
95103
tableId,
96104
params,
97105
});
98-
if (!data.length || data.length === 0) return;
99-
allRecordIds = [
100-
...data.map((record) => record.id),
101-
];
106+
107+
const allRecordIds = data.map((record) => record.id);
102108

103109
if (prevAllRecordIds) {
104-
const deletedRecordIds = prevAllRecordIds.filter(
105-
(prevRecord) => !allRecordIds.includes(prevRecord),
106-
);
110+
const currentRecordIdSet = new Set(allRecordIds);
111+
const deletedRecordIds =
112+
prevAllRecordIds.filter((prevRecord) => !currentRecordIdSet.has(prevRecord));
113+
107114
for (const recordID of deletedRecordIds) {
108-
deletedRecordsCount++;
109-
const deletedRecordObj = {
115+
const ts = Date.now();
116+
const id = `${recordID}-${ts}`;
117+
this.$emit({
118+
id: recordID,
110119
metadata,
111120
type: "record_deleted",
112-
id: recordID,
113-
};
114-
this.$emit(deletedRecordObj, {
121+
}, {
122+
id,
115123
summary: `Record deleted: ${recordID}`,
116-
id: recordID,
124+
ts,
117125
});
126+
deletedRecordsCount++;
118127
}
119128
}
120129

components/airtable_oauth/sources/new-or-modified-records-in-view/new-or-modified-records-in-view.mjs

+24-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: "New or Modified Records in View",
77
description: "Emit new event for each new or modified record in a view",
88
key: "airtable_oauth-new-or-modified-records-in-view",
9-
version: "0.0.9",
9+
version: "0.0.10",
1010
type: "source",
1111
props: {
1212
...base.props,
@@ -48,11 +48,9 @@ export default {
4848
} = this;
4949

5050
const lastTimestamp = this._getLastTimestamp();
51-
const params = {
51+
const params = this.getListRecordsParams({
5252
view: viewId,
53-
filterByFormula: `LAST_MODIFIED_TIME() > "${lastTimestamp}"`,
54-
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
55-
};
53+
});
5654

5755
const records = await this.airtable.listRecords({
5856
baseId,
@@ -74,19 +72,31 @@ export default {
7472
let newRecords = 0, modifiedRecords = 0;
7573
for (const record of records) {
7674
if (!lastTimestamp || moment(record.createdTime) > moment(lastTimestamp)) {
77-
record.type = "new_record";
75+
this.$emit({
76+
...record,
77+
type: "new_record",
78+
metadata,
79+
}, {
80+
id: record.id,
81+
summary: `New record: ${record.id}`,
82+
ts: moment(record.createdTime).valueOf(),
83+
});
7884
newRecords++;
85+
7986
} else {
80-
record.type = "record_modified";
87+
const ts = Date.now();
88+
const id = `${record.id}-${ts}`;
89+
this.$emit({
90+
...record,
91+
type: "record_modified",
92+
metadata,
93+
}, {
94+
id,
95+
summary: `Record modified: ${record.id}`,
96+
ts,
97+
});
8198
modifiedRecords++;
8299
}
83-
84-
record.metadata = metadata;
85-
86-
this.$emit(record, {
87-
summary: `${record.type}: ${JSON.stringify(record.fields)}`,
88-
id: record.id,
89-
});
90100
}
91101
console.log(`Emitted ${newRecords} new records(s) and ${modifiedRecords} modified record(s).`);
92102

components/airtable_oauth/sources/new-records-in-view/new-records-in-view.mjs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: "New Records in View",
77
description: "Emit new event for each new record in a view",
88
key: "airtable_oauth-new-records-in-view",
9-
version: "0.0.8",
9+
version: "0.0.9",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {
@@ -49,11 +49,10 @@ export default {
4949
} = this;
5050

5151
const lastTimestamp = this._getLastTimestamp();
52-
const params = {
52+
const params = this.getListRecordsParams({
5353
view: viewId,
5454
filterByFormula: `CREATED_TIME() > "${lastTimestamp}"`,
55-
returnFieldsByFieldId: this.returnFieldsByFieldId || false,
56-
};
55+
});
5756

5857
const records = await this.airtable.listRecords({
5958
baseId,

pnpm-lock.yaml

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)