You've already forked joplin
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:
@@ -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
|
||||
// the query planner from using the index. Using Postgres 16.8
|
||||
|
||||
const changesFieldsSql = fields
|
||||
.map(f => `"changes"."${f}" AS "${f}"`)
|
||||
.join(', ');
|
||||
|
||||
const subQuery2 = `
|
||||
SELECT ${fieldsSql}
|
||||
SELECT ${changesFieldsSql}
|
||||
FROM "changes"
|
||||
JOIN "user_items"
|
||||
ON user_items.item_id = changes.item_id
|
||||
WHERE counter > ?
|
||||
AND type = ?
|
||||
AND item_id IN (SELECT item_id FROM user_items WHERE user_id = ?)
|
||||
AND user_items.user_id = ?
|
||||
ORDER BY "counter" ASC
|
||||
${doCountQuery ? '' : 'LIMIT ?'}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user