@obisey/nest 0.1.30 → 0.1.31
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.
- package/package.json +1 -1
- package/prototipos/baseService.js +45 -14
package/package.json
CHANGED
|
@@ -161,18 +161,28 @@ function BaseService(modelo) {
|
|
|
161
161
|
}
|
|
162
162
|
// SAVE ITEMS HERE (before transform)
|
|
163
163
|
console.log(`[PEDIR-SAVING-ITEMS] ${modelo}: saving ${result.length} items to Redis`);
|
|
164
|
-
const savePromises = result.map((item) => {
|
|
164
|
+
const savePromises = result.map((item, idx) => {
|
|
165
165
|
const id = (0, getModelId_1.getModelId)(item);
|
|
166
166
|
const plainData = item.get({ plain: true });
|
|
167
|
-
|
|
167
|
+
console.log(`[PEDIR-ITEM-${idx}] ${modelo}: id=${id}, saving to pkey=${pkey(id).substring(0, 50)}`);
|
|
168
|
+
return this.redis.hSet(pkey(id), 'item', JSON.stringify(plainData))
|
|
169
|
+
.then(res => {
|
|
170
|
+
console.log(`[PEDIR-ITEM-${idx}-SAVED] ${modelo}: id=${id}, result=${res}`);
|
|
171
|
+
return res;
|
|
172
|
+
})
|
|
173
|
+
.catch(err => {
|
|
174
|
+
console.log(`[PEDIR-ITEM-${idx}-ERROR] ${modelo}: id=${id}, error=${err.message}`);
|
|
175
|
+
throw err;
|
|
176
|
+
});
|
|
168
177
|
});
|
|
169
178
|
Promise.all(savePromises)
|
|
170
179
|
.then(() => {
|
|
171
|
-
console.log(`[PEDIR-ITEMS-SAVED] ${modelo}: all items saved`);
|
|
180
|
+
console.log(`[PEDIR-ITEMS-SAVED] ${modelo}: all ${result.length} items saved successfully`);
|
|
181
|
+
console.log(`[PEDIR-BEFORE-RESOLVE] ${modelo}: about to resolve with ${result.length} items`);
|
|
172
182
|
resolve(result);
|
|
173
183
|
})
|
|
174
184
|
.catch(err => {
|
|
175
|
-
console.log(`[PEDIR-SAVE-ERROR] ${modelo}
|
|
185
|
+
console.log(`[PEDIR-SAVE-ERROR] ${modelo}: error=${err.message}, but resolving anyway with ${result.length} items`);
|
|
176
186
|
resolve(result);
|
|
177
187
|
});
|
|
178
188
|
});
|
|
@@ -180,44 +190,65 @@ function BaseService(modelo) {
|
|
|
180
190
|
() => new Promise(async (resolve) => {
|
|
181
191
|
console.log(`[OBSERVAR-START] ${modelo}: checking Redis for nkey=${nkey.substring(0, 50)}`);
|
|
182
192
|
let e = await this.redis.hExists(nkey, peticion);
|
|
183
|
-
console.log(`[OBSERVAR-EXISTS] ${modelo}:
|
|
193
|
+
console.log(`[OBSERVAR-EXISTS] ${modelo}: hExists result=${e}`);
|
|
184
194
|
if (e) {
|
|
185
195
|
let ids = await this.redis.hGet(nkey, peticion);
|
|
186
|
-
console.log(`[OBSERVAR-IDS] ${modelo}:
|
|
196
|
+
console.log(`[OBSERVAR-IDS] ${modelo}: hGet returned=${ids ? ids.substring(0, 60) : 'NULL'}`);
|
|
187
197
|
if (ids) {
|
|
188
|
-
|
|
198
|
+
const idArray = JSON.parse(ids);
|
|
199
|
+
console.log(`[OBSERVAR-IDS-PARSED] ${modelo}: parsed ${idArray.length} IDs=[${idArray.join(',')}]`);
|
|
200
|
+
Promise.all(idArray.map(async (id, idx) => {
|
|
201
|
+
const exists = await this.redis.hExists(pkey(id), 'item');
|
|
202
|
+
console.log(`[OBSERVAR-EXISTS-${idx}] ${modelo}: id=${id}, hExists(pkey(id), 'item')=${exists}`);
|
|
203
|
+
return exists;
|
|
204
|
+
})).then((exists) => {
|
|
205
|
+
console.log(`[OBSERVAR-EXISTS-ARRAY] ${modelo}: all checks done, exists=[${exists}], includes(0)=${exists.includes(0)}`);
|
|
189
206
|
if (!exists.includes(0)) {
|
|
190
207
|
console.log(`[OBSERVAR-ALL-EXIST] ${modelo}: all items exist, fetching from Redis`);
|
|
191
|
-
Promise.all(
|
|
208
|
+
Promise.all(idArray.map(async (id, idx) => {
|
|
209
|
+
const item = await this.redis.hGet(pkey(id), 'item');
|
|
210
|
+
console.log(`[OBSERVAR-HGET-${idx}] ${modelo}: id=${id}, hGet(pkey(id), 'item')=${item ? item.substring(0, 60) : 'NULL'}`);
|
|
211
|
+
return item;
|
|
212
|
+
})).then(items => {
|
|
192
213
|
console.log(`[OBSERVAR-RESOLVE-ITEMS] ${modelo}: resolving ${items.length} items from Redis`);
|
|
193
214
|
console.log(`[OBSERVAR-ITEMS-CONTENT] ${modelo}: [0]=${items[0] ? items[0].substring(0, 80) : 'NULL'}`);
|
|
215
|
+
console.log(`[OBSERVAR-ITEMS-NULL-COUNT] ${modelo}: ${items.filter(i => i === null).length} NULL items out of ${items.length}`);
|
|
194
216
|
resolve(items);
|
|
195
217
|
});
|
|
196
218
|
}
|
|
197
219
|
else {
|
|
198
|
-
console.log(`[OBSERVAR-INCOMPLETE] ${modelo}: some items missing
|
|
220
|
+
console.log(`[OBSERVAR-INCOMPLETE] ${modelo}: some items missing. exists.includes(0)=true, fallback to DB`);
|
|
199
221
|
resolve(undefined);
|
|
200
222
|
}
|
|
201
223
|
});
|
|
202
224
|
}
|
|
203
225
|
else {
|
|
204
|
-
console.log(`[OBSERVAR-NO-IDS] ${modelo}: no IDs in Redis, fallback to DB`);
|
|
226
|
+
console.log(`[OBSERVAR-NO-IDS] ${modelo}: hGet returned null, no IDs in Redis, fallback to DB`);
|
|
205
227
|
resolve(undefined);
|
|
206
228
|
}
|
|
207
229
|
}
|
|
208
230
|
else {
|
|
209
|
-
console.log(`[OBSERVAR-NOT-EXISTS] ${modelo}: nkey not in Redis, fallback to DB`);
|
|
231
|
+
console.log(`[OBSERVAR-NOT-EXISTS] ${modelo}: hExists returned false, nkey not in Redis, fallback to DB`);
|
|
210
232
|
resolve(undefined);
|
|
211
233
|
}
|
|
212
234
|
}), //observar
|
|
213
235
|
(__, resultado) => {
|
|
214
|
-
console.log(`[ACTUALIZAR-START] ${modelo}: saving IDs to Redis`);
|
|
236
|
+
console.log(`[ACTUALIZAR-START] ${modelo}: saving IDs to Redis, nkey=${nkey.substring(0, 50)}, peticion=${peticion.substring(0, 30)}`);
|
|
215
237
|
const idsToSave = resultado.map((n) => {
|
|
216
238
|
// resultado is already transformed to plain JSON
|
|
217
239
|
return n.id || n;
|
|
218
240
|
});
|
|
219
|
-
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
|
|
220
|
-
|
|
241
|
+
console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}], count=${idsToSave.length}`);
|
|
242
|
+
console.log(`[ACTUALIZAR-BEFORE-HSET] ${modelo}: about to hSet(${nkey.substring(0, 40)}, ${peticion.substring(0, 20)}, [IDs])`);
|
|
243
|
+
return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave))
|
|
244
|
+
.then(res => {
|
|
245
|
+
console.log(`[ACTUALIZAR-HSET-SUCCESS] ${modelo}: result=${res}`);
|
|
246
|
+
return res;
|
|
247
|
+
})
|
|
248
|
+
.catch(err => {
|
|
249
|
+
console.log(`[ACTUALIZAR-HSET-ERROR] ${modelo}: error=${err.message}`);
|
|
250
|
+
throw err;
|
|
251
|
+
});
|
|
221
252
|
});
|
|
222
253
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
223
254
|
// if (isDev)
|