Closed karenc closed 8 years ago
The changes look okay to me, I would just address the one comment I had where a boolean argument carries some context with it in callers. Thanks karen :)
@joemsak Can you have a look again? If you have time, try it on your tutor-server ecosystems import page to see if it loads faster?
@jpslav I've looked at your changes in #40 and turns out it doesn't really fix this issue. So I'll have to rebase #40 after this.
@karenc I just took a look at PR 40 and I think it does fix the issue. The spec from this PR didn't show it exactly because in my PR, I changed new
to no longer write to the store. So the
let!(:job) { described_class.new }
line in the spec didn't really put anything in the store, and then the find!
call had to create it, so the spec was failing. I copied your spec over and changed described_class.new
to described_class.create
and changed find
to find!
(which is the new method name to show that it will create a job in the store if it isn't found). Here's the commit:
Does that make sense?
I added another commit that adds a find
method in addition to the existing find!
method. find
returns nil if the job is not in the store, whereas the bang version creates an unknown status job if not in the store.
https://github.com/lml/lev/commit/d2f1272f6af9599f2a1d17c5e415b57cd20e7369
Thanks for explaining it to me. Let me pick out the bits that we need to fix this slowness issue. (Will open another pull request as the code is going to be very different)
Lev::BackgroundJob.find
was writing to store which causesLev::BackgroundJob.all
to be very slow..find
needs to create a new instance ofLev::BackgroundJob
but does not need to write to store.The performance improvement on tutor-server for 1174 background jobs is more than 10 times. Doing
Lev::BackgroundJob.all
took 1.58s, now it only takes 0.14s.