Skip to content

Add assets index for app and folder queries - #1345

Closed
NoahHahm wants to merge 1 commit into
Squidex:masterfrom
NoahHahm:fix/index
Closed

NoahHahm wants to merge 1 commit into
Squidex:masterfrom
NoahHahm:fix/index

Conversation

@NoahHahm

@NoahHahm NoahHahm commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1344

What

Adds an index { _ai: 1, pi: 1, mt: -1, id: 1 } to States_Assets2.

Why

The assets query filters by app and parent folder and sorts by mt desc, id asc. The existing index starts with mt, so MongoDB walks the index in mt order across the whole collection and filters afterwards. With a large collection this makes root folder queries and their total count very slow, and they hit assets.timeoutQuery (408).

The new index starts with the equality fields (_ai, pi) and then follows the sort order, so the query and the count only read the requested folder.

@NoahHahm

NoahHahm commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

hi. @SebastianStehle
I have resolved the issue using this index for now.
If there is a better alternative, feel free to close the PR.

@SebastianStehle

Copy link
Copy Markdown
Contributor

I think we have to check out the indexes and see if they match with the queries. Just having an additional index is not necessarily the best idea

@NoahHahm

NoahHahm commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

I think we have to check out the indexes and see if they match with the queries. Just having an additional index is not necessarily the best idea

I agree.
If there is room for improvement without adding an index, I think that is a good approach.

@SebastianStehle

Copy link
Copy Markdown
Contributor

I have pushed a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Asset Query 408 Timeout

2 participants