Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite tree search queries using MongoDB $graphLookup #238

Open
amoeba opened this issue Jun 4, 2024 · 0 comments
Open

Rewrite tree search queries using MongoDB $graphLookup #238

amoeba opened this issue Jun 4, 2024 · 0 comments

Comments

@amoeba
Copy link
Owner

amoeba commented Jun 4, 2024

When I originally wrote this codebase, MongoDB didn't have a built-in way to do graph traversal so my solution was to use a loop (originally, recursion), see https://github.com/amoeba/treestats.net/blob/main/helpers/chain_helper.rb#L68. The problem with this is that it's slow and scales poorly: We issue a query for each node in the tree which hammers the database and can take many seconds to finish.

Since MongoDB 3.4, the $graphLookup aggregation stage seems like it can do this all for us in one query which should be orders of magnitude faster.

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

No branches or pull requests

1 participant