rads-db 3.0.76 → 3.0.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -124,14 +124,31 @@ var _default = options => (schema, entity) => {
124
124
  ...item
125
125
  });
126
126
  }
127
- for (const chunk of _lodash.default.chunk(itemsToPut, 200)) {
128
- const response = await client.items.bulk(chunk.map(x => ({
127
+ for (const chunk of _lodash.default.chunk(itemsToPut, 100)) {
128
+ let chunkToSend = chunk.map(x => ({
129
129
  operationType: "Upsert",
130
130
  resourceBody: x
131
- })));
131
+ }));
132
+ const responses = [];
133
+ for (let i = 0; i < 20; i++) {
134
+ const response = await client.items.bulk(chunkToSend);
135
+ const newChunkToSend = [];
136
+ for (let i2 = 0; i2 < chunkToSend.length; i2++) {
137
+ if (response[i2].statusCode !== 429) {
138
+ responses.push(response[i2]);
139
+ } else {
140
+ newChunkToSend.push(chunkToSend[i2]);
141
+ }
142
+ }
143
+ chunkToSend = newChunkToSend;
144
+ if (chunkToSend.length === 0) break;
145
+ const delay = 50 + i * 100;
146
+ console.warn(`Db overloaded. Retrying after ${delay}ms...`);
147
+ await new Promise(resolve => setTimeout(resolve, delay));
148
+ }
132
149
  ctx?.log?.({
133
- charge: _lodash.default.sumBy(response, r => r.requestCharge),
134
- request: `put#${itemsToPut[0]._partition}[${chunk.length}]`
150
+ charge: _lodash.default.sumBy(responses, r => r.requestCharge),
151
+ request: `put#${chunk[0]._partition}[${chunk.length}]`
135
152
  });
136
153
  }
137
154
  }
@@ -80,16 +80,32 @@ export default (options) => (schema, entity) => {
80
80
  throw new Error(`You must provide an id`);
81
81
  itemsToPut.push({ _partition: entity, id, ...item });
82
82
  }
83
- for (const chunk of _.chunk(itemsToPut, 200)) {
84
- const response = await client.items.bulk(
85
- chunk.map((x) => ({
86
- operationType: "Upsert",
87
- resourceBody: x
88
- }))
89
- );
83
+ for (const chunk of _.chunk(itemsToPut, 100)) {
84
+ let chunkToSend = chunk.map((x) => ({
85
+ operationType: "Upsert",
86
+ resourceBody: x
87
+ }));
88
+ const responses = [];
89
+ for (let i = 0; i < 20; i++) {
90
+ const response = await client.items.bulk(chunkToSend);
91
+ const newChunkToSend = [];
92
+ for (let i2 = 0; i2 < chunkToSend.length; i2++) {
93
+ if (response[i2].statusCode !== 429) {
94
+ responses.push(response[i2]);
95
+ } else {
96
+ newChunkToSend.push(chunkToSend[i2]);
97
+ }
98
+ }
99
+ chunkToSend = newChunkToSend;
100
+ if (chunkToSend.length === 0)
101
+ break;
102
+ const delay = 50 + i * 100;
103
+ console.warn(`Db overloaded. Retrying after ${delay}ms...`);
104
+ await new Promise((resolve) => setTimeout(resolve, delay));
105
+ }
90
106
  ctx?.log?.({
91
- charge: _.sumBy(response, (r) => r.requestCharge),
92
- request: `put#${itemsToPut[0]._partition}[${chunk.length}]`
107
+ charge: _.sumBy(responses, (r) => r.requestCharge),
108
+ request: `put#${chunk[0]._partition}[${chunk.length}]`
93
109
  });
94
110
  }
95
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rads-db",
3
- "version": "3.0.76",
3
+ "version": "3.0.77",
4
4
  "packageManager": "pnpm@8.6.1",
5
5
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
6
6
  "author": "",