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

Optimize performance of job tables #11

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/kuiq/model/job_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def sorted_jobs(klass)
inst = klass.new
key = inst.name
count = inst.size
page_size = 25
page_data_cache = nil
Enumerator::Lazy.new(count.times, count) do |yielder, index|
page = index + 1
page_index = index/page_size
page = page_index + 1
index_within_page = index % page_size
count = 1
job_redis_hash_json, score = Paginator.instance.page(key, page, 1).last.reject { |j| j.is_a?(Numeric) }.first
page_data_cache = nil if index_within_page == 0
page_data_cache ||= Paginator.instance.page(key, page, page_size)
job_redis_hash_json, score = page_data_cache.last.reject { |j| j.is_a?(Numeric) }[index_within_page]
if job_redis_hash_json
job_redis_hash = JSON.parse(job_redis_hash_json)
yielder << Job.new(job_redis_hash, score, index)
Expand Down