1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Server: Optimise delta sub-query (#13633)

This commit is contained in:
Laurent Cozic
2025-11-06 20:27:47 +01:00
committed by GitHub
parent 996a0894ae
commit aaeb5db3c7

View File

@@ -167,12 +167,18 @@ export default class ChangeModel extends BaseModel<Change> {
// 2025-11-06: Remove the "+ 0" because now it appears to make query slower by preventing // 2025-11-06: Remove the "+ 0" because now it appears to make query slower by preventing
// the query planner from using the index. Using Postgres 16.8 // the query planner from using the index. Using Postgres 16.8
const changesFieldsSql = fields
.map(f => `"changes"."${f}" AS "${f}"`)
.join(', ');
const subQuery2 = ` const subQuery2 = `
SELECT ${fieldsSql} SELECT ${changesFieldsSql}
FROM "changes" FROM "changes"
JOIN "user_items"
ON user_items.item_id = changes.item_id
WHERE counter > ? WHERE counter > ?
AND type = ? AND type = ?
AND item_id IN (SELECT item_id FROM user_items WHERE user_id = ?) AND user_items.user_id = ?
ORDER BY "counter" ASC ORDER BY "counter" ASC
${doCountQuery ? '' : 'LIMIT ?'} ${doCountQuery ? '' : 'LIMIT ?'}
`; `;