mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 20:22:54 -06:00
perf(api): otimiza paginação em fetchChats usando LIMIT/OFFSET no SQL
This commit is contained in:
parent
b94b452597
commit
095754d173
@ -697,6 +697,9 @@ export class ChannelStartupService {
|
|||||||
AND "Message"."messageTimestamp" <= ${Math.floor(new Date(query.where.messageTimestamp.lte).getTime() / 1000)}`
|
AND "Message"."messageTimestamp" <= ${Math.floor(new Date(query.where.messageTimestamp.lte).getTime() / 1000)}`
|
||||||
: Prisma.sql``;
|
: Prisma.sql``;
|
||||||
|
|
||||||
|
const limit = query?.take ? Prisma.sql`LIMIT ${query.take}` : Prisma.sql``;
|
||||||
|
const offset = query?.skip ? Prisma.sql`OFFSET ${query.skip}` : Prisma.sql``;
|
||||||
|
|
||||||
const results = await this.prismaRepository.$queryRaw`
|
const results = await this.prismaRepository.$queryRaw`
|
||||||
WITH rankedMessages AS (
|
WITH rankedMessages AS (
|
||||||
SELECT DISTINCT ON ("Message"."key"->>'remoteJid')
|
SELECT DISTINCT ON ("Message"."key"->>'remoteJid')
|
||||||
@ -732,7 +735,9 @@ export class ChannelStartupService {
|
|||||||
ORDER BY "Message"."key"->>'remoteJid', "Message"."messageTimestamp" DESC
|
ORDER BY "Message"."key"->>'remoteJid', "Message"."messageTimestamp" DESC
|
||||||
)
|
)
|
||||||
SELECT * FROM rankedMessages
|
SELECT * FROM rankedMessages
|
||||||
ORDER BY "updatedAt" DESC NULLS LAST;
|
ORDER BY "updatedAt" DESC NULLS LAST
|
||||||
|
${limit}
|
||||||
|
${offset};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (results && Array.isArray(results) && results.length > 0) {
|
if (results && Array.isArray(results) && results.length > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user