Close two minor gaps flagged by round-2 re-review of listLeads split
Drop any row whose id disappeared between the id-pagination query and the hydrate query (e.g. a lead deleted by a base reset mid-request) instead of leaking an undefined hole into the response. Document that SORTS may only reference leads columns, since the id-pagination query no longer joins segments.
This commit is contained in:
@@ -24,6 +24,10 @@ function sharedNumberColumnsSql(column) {
|
|||||||
) END AS numero_compartilhado_override_raw`;
|
) END AS numero_compartilhado_override_raw`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// So colunas de `leads`: a paginacao de listLeads roda uma consulta so-id sem
|
||||||
|
// o LEFT JOIN de segments antes de hidratar a pagina, entao um sort aqui que
|
||||||
|
// referencie uma coluna de outra tabela (ex.: segments.affinity) quebraria
|
||||||
|
// essa consulta.
|
||||||
const SORTS = {
|
const SORTS = {
|
||||||
'prioridade:asc': 'prioridade ASC, score DESC, cidade ASC, empresa ASC',
|
'prioridade:asc': 'prioridade ASC, score DESC, cidade ASC, empresa ASC',
|
||||||
'score:desc': 'score DESC, empresa ASC',
|
'score:desc': 'score DESC, empresa ASC',
|
||||||
@@ -125,7 +129,10 @@ export function listLeads(db, filtro = {}) {
|
|||||||
).all(...pageIds)
|
).all(...pageIds)
|
||||||
.map((lead) => [lead.id, withSharedNumberState(withWhatsAppState(db, lead))]));
|
.map((lead) => [lead.id, withSharedNumberState(withWhatsAppState(db, lead))]));
|
||||||
|
|
||||||
const rows = pageIds.map((id) => rowsById.get(id));
|
// filter(Boolean): as duas consultas nao rodam na mesma transacao, entao um
|
||||||
|
// lead da pagina pode ser removido (reset da base) entre uma e outra — sem
|
||||||
|
// isso, esse id sobraria como buraco `undefined` na resposta.
|
||||||
|
const rows = pageIds.map((id) => rowsById.get(id)).filter(Boolean);
|
||||||
|
|
||||||
return { total, page, pageSize, rows };
|
return { total, page, pageSize, rows };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user