-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conditionally load job classes #2758
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2758 +/- ##
===========================================
+ Coverage 67.1% 67.3% +0.2%
+ Complexity 4675 4673 -2
===========================================
Files 479 479
Lines 19548 19539 -9
===========================================
+ Hits 13116 13158 +42
+ Misses 6432 6381 -51
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing I wanted to confirm that at least one of each specific job type was tested. Since a lot of jobs share base classes I didn't add test instructions for every single job as we aren't changing the functionality of the jobs, just how / when they are initialized. For notes specifically it was my intention to refactor this at a later stage (if there are optimizations to be done) to ensure they are only loaded when needed. |
Changes proposed in this Pull Request:
This PR changes the behaviour for loading Job classes. This is part of a series of performance improvements, each change doesn't make a major difference but every little helps reduce the load.
The class
JobInitializer
already had ais_needed
which should prevent the functionality from running on the frontend. However the way the code was structured all the job classes were loaded even if they are never used. So this PR went through several steps to ensure they are only loaded when actually used.The first step was to prevent
interface JobInterface
from extendinginterface Service
. There is no need for each individual job to be a service as the JobRepository can handle the management of these classes. All services are loaded when we callmaybe_register_services
, so by removing this, we prevent the container from loading the job classes both when fetchingService
and later forJobInterface
, only the latter is needed.The second issue was that the
JobRepository
was being passed a list of all jobs in the constructor. This was changed to provide the container, so the JobRepository can load the jobs when needed, only when theis_needed
function returns true (so we don't have to load them on frontend requests).Also in SyncerHooks we should load jobs only once the hook is triggered (not in the constructor). This prevents them from loading too early, where they might not even be needed in the request.
We also ensure that the JobRepository is used consistently throughout the code, which will make it easier for any future optimizations.
The timing isn't exact as there are a lot of things which can be cached, but if we compare some of the profiling for front end requests before and after the changes we can see some significant changes in how many classes need to be resolved.
Before:
After:
Resolves part of #1250
Detailed test instructions:
The functionality of the code wasn't changed, so the core thing to test is that scheduled jobs continue to run in the same way as they used to.
Test syncing single product
gla/jobs/update_products/process_item
is completed without issuesTest syncing all products
/wp-admin/admin.php?page=connection-test-admin-page
gla/jobs/update_all_products/create_batch
andgla/jobs/update_all_products/process_item
(depends on how many products there are)Test restoring recurring actions
wc_gla_cron_daily_notes
andgla/jobs/resubmit_expiring_products/start
Changelog entry