Skip to content

Commit 288dfed

Browse files
committed
fix: add blob processing to replace(), cap list() parallelism, document bulkCreate non-atomicity
1 parent b223e25 commit 288dfed

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/data.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ export class DataManager {
5050
const result = await handleResponse<any>(response);
5151
const items: any[] = Array.isArray(result) ? result : result?.data ?? result ?? [];
5252
if (this.blobManager) {
53-
return Promise.all(items.map((item) => this.blobManager!.processForRead(item, token)));
53+
// Process items sequentially to avoid unbounded parallel downloads.
54+
// Each item already uses internal parallelism (MAX_CONCURRENT=6) for its blobs.
55+
const resolved: any[] = [];
56+
for (const item of items) {
57+
resolved.push(await this.blobManager.processForRead(item, token));
58+
}
59+
return resolved;
5460
}
5561
return items;
5662
}
@@ -107,13 +113,16 @@ export class DataManager {
107113
*/
108114
async replace(table: string, id: string, obj: any, token: string): Promise<any> {
109115
const url = `${this.dbUrl}/${encodeURIComponent(table)}/${encodeURIComponent(id)}`;
116+
const body = this.blobManager
117+
? await this.blobManager.processForUpload(obj, token)
118+
: obj;
110119
const response = await this.http.fetch(url, {
111120
method: 'PUT',
112121
headers: {
113122
Authorization: `Bearer ${token}`,
114123
'Content-Type': 'application/json',
115124
},
116-
body: stringifyBody(obj),
125+
body: stringifyBody(body),
117126
});
118127
return handleResponse<any>(response);
119128
}
@@ -149,6 +158,9 @@ export class DataManager {
149158
/**
150159
* Bulk create objects in a table in parallel.
151160
* All requests are sent concurrently via Promise.all.
161+
*
162+
* NOTE: This is NOT atomic — if one create fails, others may have already
163+
* succeeded on the server. There is no rollback for partial failures.
152164
*/
153165
async bulkCreate(table: string, objects: any[], token: string): Promise<any[]> {
154166
return Promise.all(objects.map((obj) => this.create(table, obj, token)));

0 commit comments

Comments
 (0)