3 Commits

Author SHA1 Message Date
edreitega f86c4d4f2a Merge pull request 'SPI-007: optimizar count de préstamos activos con vista ligera' (#4) from feature/SPI-007-prestamos-activos-timeout into dev
Reviewed-on: #4
2026-06-29 17:31:33 +00:00
Edrei Téllez ffb2a1d64a SPI-007: optimizar count de préstamos activos con vista ligera
Separar find (full view) del count (informacion_prestamo_view) en el path
activo=true con paginación para evitar timeout por COUNT sobre 8 JOINs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 11:06:27 -06:00
edreitega 8e74802de7 Merge pull request 'SEC-001: migrar HcaptchaGuard a TurnstileGuard con siteverify Cloudflare.' (#2) from feature/SEC-001-turnstile into dev
Reviewed-on: #2
2026-06-23 10:37:03 -06:00
+28 -8
View File
@@ -450,15 +450,35 @@ export class PrestamoService {
if (filtros.pagina) {
options.take = 25;
options.skip = (parseInt(filtros.pagina) - 1) * 25;
return this.fullInformacionPrestamoView
.findAndCount(options)
.then((infoPrestamos) => {
const prestamos: Prestamo[] = [];
for (let i = 0; i < infoPrestamos[0].length; i++)
prestamos.push(this.fullViewToPrestamo(infoPrestamos[0][i]));
return [prestamos, infoPrestamos[1]];
});
const activoTrue =
(typeof filtros.activo === 'boolean' && filtros.activo) ||
(typeof filtros.activo === 'string' && filtros.activo === 'true');
const canUseLightCount =
activoTrue && !filtros.usuario && !filtros.id_tipo_usuario;
if (canUseLightCount) {
const { usuario: _u, id_tipo_usuario: _tu, ...countWhere } =
busqueda;
const [rows, total] = await Promise.all([
this.fullInformacionPrestamoView.find(options),
this.informacionPrestamoView.count({
where: countWhere as FindOptionsWhere<InformacionPrestamoView>,
}),
]);
const prestamos = rows.map((row) => this.fullViewToPrestamo(row));
return [prestamos, total];
}
const infoPrestamos = await this.fullInformacionPrestamoView.findAndCount(
options,
);
const prestamos: Prestamo[] = [];
for (let i = 0; i < infoPrestamos[0].length; i++)
prestamos.push(this.fullViewToPrestamo(infoPrestamos[0][i]));
return [prestamos, infoPrestamos[1]];
}
options.order = { id_institucion: 'ASC', id_prestamo: 'ASC' };
return this.fullInformacionPrestamoView.find(options);