Searching in OrderedMap

It might sound like a simple question, but I’m currently facing challenges when querying an OrderedMap with around 50,000 entries.

Let’s assume the map uses an id as the key and a record as the value. This record contains fields such as userId, projectId, and others. I want to filter tasks based on one or more of these fields — either individually or in combination.

So my question is: What is the best strategy to implement such filtering without hitting the Wasm execution or complexity limits?

Even paging is a topic.

We are currently using stable btree maps everywhere and we faced the same situation. In order to avoid that we had to implement indexes.

Also for lookups Btree is O(log n) so probably faster than OrderedMap O(n)

Have a look here:

1 Like

Yes, using a secondary index seems to be the right approach. However, the real challenge in my case is updating the index — this is where I consistently hit the Wasm complexity limit. How do you update the index or keep the index in sync in case of adding a new entry or updating an existing?