Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "google-ads-api",
"version": "21.0.1",
"version": "21.0.2-beta.1",
"description": "Google Ads API Client Library for Node.js",
"repository": "https://github.com/Opteo/google-ads-api",
"main": "build/src/index.js",
Expand Down
47 changes: 30 additions & 17 deletions src/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,29 +494,42 @@ export class Customer extends ServiceFactory {
packValues: true,
packKeys: true,
});
const streamArrayInstance = streamArray();

const pipeline = chain([stream, parser, streamArray()]);
const pipeline = chain([stream, parser, streamArrayInstance]);
let count = 0;

for await (const data of pipeline) {
const results =
data.value.results ??
(data.value.summaryRow ? [data.value.summaryRow] : undefined) ??
[];
try {
for await (const data of pipeline) {
const results =
data.value.results ??
(data.value.summaryRow ? [data.value.summaryRow] : undefined) ??
[];

count += results.length;
if (
this.clientOptions.max_reporting_rows &&
count > this.clientOptions.max_reporting_rows &&
!this.gaqlQueryStringIncludesLimit(gaqlQuery)
) {
throw this.generateTooManyRowsError();
}

count += results.length;
if (
this.clientOptions.max_reporting_rows &&
count > this.clientOptions.max_reporting_rows &&
!this.gaqlQueryStringIncludesLimit(gaqlQuery)
) {
throw this.generateTooManyRowsError();
}
for (const row of results) {
const parsed = this.decamelizeKeysIfNeeded(row);
yield parsed as T;
}

for (const row of results) {
const parsed = this.decamelizeKeysIfNeeded(row);
yield parsed as T;
// Clear references to help GC
data.value = null;
data.key = null;
}
} finally {
// Always destroy all components to prevent memory leaks
pipeline.destroy();
parser.destroy();
streamArrayInstance.destroy();
stream.destroy();
}

return;
Expand Down
Loading