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

Improve performance of query jobs by owner #40

Open
dev8723 opened this issue Jul 23, 2023 · 0 comments
Open

Improve performance of query jobs by owner #40

dev8723 opened this issue Jul 23, 2023 · 0 comments

Comments

@dev8723
Copy link
Contributor

dev8723 commented Jul 23, 2023

When we are designing asset lock (#38), I found it's important to be able to efficiently query jobs by their owner (say get all pending jobs created by terra123), currently jobs are stored in an index map where key is job_id, index keys include reward and publish_time. In currently implementation, get all jobs by owner will take O(N) complexity as we need to go over all jobs, which is very slow.

More importantly, if we want to query this onchain as part of some contract execution (say query all pending jobs by owner and calculate the total locked assets as part of withdraw asset), it's likely to take too much gas when there are lots of jobs in the future, we propose 2 solutions.

  1. Add the owner as a new index, this should reduce complexity to O(logN) I believe, but we already have 2 index keys, not sure if we should keep adding it.
  2. Create another map key is owner, value is list of job ids from owned jobs. I prefer this approach as it's O(1) and since we only store job id in the value, it shouldn't take too much additional space.
@dev8723 dev8723 changed the title Improve query jobs by owner performance Improve performance of query jobs by owner Jul 28, 2023
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

No branches or pull requests

1 participant