Commit Graph
3 Commits
Author SHA1 Message Date
Lauri Ojansivu 8dc77a89d8 Indexes for the LDAP id, cards' assignees and members, and History by entity and hash.
On a large installation the database-problems page filled with collection
scans of queries WeKan makes constantly but never indexed: a user looked
up by services.ldap.id at every LDAP login and sync pass (13,000+ users,
~430 ms per login), cards by assignees or members across every board for
My Cards and the filters (1.1M cards, 1-3.7 s, dozens of times a minute),
and changeHistory by entity and by integrity hash (120,000+ rows, and
growing). Each now has an index, created at startup with ensureIndex like
every other one: services.ldap.id sparse, assignees and members both so
their $or uses an index on each branch, and changeHistory's
{ entityType, entityId, createdAt } and { integrityHash }.

Thanks to Raymond-Voogt and xet7 !

Fixes #6892.
2026-11-11 20:29:31 +02:00
Lauri Ojansivu 0c6c0c6021 Index cards.parentIds, so finding subtasks no longer scans every card.
Since a card can be a subtask of several parents (v12.10), its children are
found with { $or: [{ parentId }, { parentIds }] }. Only parentId had an
index, and a $or uses indexes only when every branch has one, so the query
was a collection scan - in the card remove hook for every removed card, in
card copy and in the Excel and PDF exporters. parentIds now has its own
index beside parentId's.

tests/cardQueryIndexes.test.cjs reads the branches of every $or in
models/lib/cardParents.js and requires an index for each field, so a new
branch cannot arrive without one.

Thanks to Raymond-Voogt and xet7 !

Fixes #6770.
2026-10-14 16:43:35 +03:00
Lauri Ojansivu 569dd4af54 Index the collections a card is made of.
Reported by email against 10.91: "Still slow on loading cards. Test server with
me as only user." One user is the part that says what it is not: with nobody
else on the server there is no contention, no queue and no lock, so the time is
going into the queries themselves.

It was. cards, activities, cardComments, checklists and checklistItems - every
collection a board draws and an opened card pulls in - had NO index at all.
"The cards of this list", "the comments of this card", "the newest activities of
this board" each walked the whole collection. That is invisible on a demo board
and expensive on a real one, and worse on FerretDB, whose SQLite backend has to
walk the same documents. The activities publication even explains that it keeps
its selector flat so it can push down to FerretDB's index; there was no index
for it to push down to.

Each index matches a selector the app really makes WITH the sort it really uses
- boardId+archived, listId+sort, swimlaneId+sort, parentId, boardId+cardNumber
for cards; cardId+createdAt and boardId+createdAt for activities and comments;
cardId+sort and checklistId+sort for the checklists - because an index on the
filter alone still leaves an in-memory sort of everything it matched, which on a
board with a year of history is the slow half.

They go through the same idempotent ensureIndex every other index here uses: it
waits for the replica-set primary, does nothing when the index is already there,
and logs a backend that refuses one instead of stopping the server.

tests/cardQueryIndexes.test.cjs pins the set, and that each one carries the sort
as well as the filter.

Thanks to xet7 !
2026-08-14 13:58:44 +03:00