User tests: Successful: Unsuccessful:
PlgSystemSchedulerunner::injectLazyJS()
checks the presence of due tasks via weird loading of items list with order by title DESC using the admin model:
SELECT a.id, a.asset_id, a.title, a.type, a.execution_rules, a.state, a.last_exit_code, a.locked, a.last_execution, a.next_execution, a.times_executed, a.times_failed, a.ordering, a.note
FROM `jos_scheduler_tasks` AS `a`
WHERE `a`.`state` = :state AND `a`.`next_execution` <= :now
ORDER BY `a`.`title` desc
Assuming that we are not loading the data but only counting the tasks which should be executed, we should not retrieve the full list of items, but only count them.
We have a second weird query to check if there are any locked tasks, the same invalid behavior occurs again:
SELECT a.id, a.asset_id, a.title, a.type, a.execution_rules, a.state, a.last_exit_code, a.locked, a.last_execution, a.next_execution, a.times_executed, a.times_failed, a.ordering, a.note
FROM `#__scheduler_tasks` AS `a`
WHERE `a`.`state` = :state AND `a`.`locked` IS NOT NULL
ORDER BY `a`.`title` desc
These two queries can be optimized into single efficient query which loads the number of due tasks + the number of locked tasks:
SELECT SUM(CASE WHEN `a`.`next_execution` <= :now THEN 1 ELSE 0 END) AS due_count, SUM(CASE WHEN `a`.`locked` IS NULL THEN 0 ELSE 1 END) AS locked_count
FROM `#__scheduler_tasks` AS `a`
WHERE `a`.`state` = :state
Using backend list model is not efficient, better compose the query in the plugin.
The result of single query is checked and the plugin is not adding JS if we don't have due tasks OR we have locked tasks.
Test scheduled tasks
See two queries for #__scheduler_tasks
table.
See one query for #__scheduler_tasks
table.
com_scheduler works as before.
No.
Status | New | ⇒ | Pending |
Category | ⇒ | Front End Plugins |
Labels |
Added:
?
|
Labels |
Added:
?
|
Category | Front End Plugins | ⇒ | Administration Front End Plugins |
This pull request has automatically rebased to 4.2-dev.
This pull requests has been automatically converted to the PSR-12 coding standard.
Labels |
Added:
?
?
Removed: ? ? |
Labels |
Removed:
?
|
Labels |
Added:
PR-4.3-dev
Removed: ? |
Title |
|
Labels |
Added:
bug
|
Can you fix the conflict?
Labels |
Added:
PR-4.4-dev
Removed: PR-4.3-dev |
Sorry i missed that one
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-09-11 20:07:34 |
Closed_By | ⇒ | MacJoom |
It was a deliberate decision to avoid any queries that bypass the model. That said I really like this, but could we instead add this as a method in the Scheduler model which could be then accessed through the Scheduler API class? That way we could avoid any localized logic in the plugin and also increase the useful API surface of the Scheduler which could be useful to other extensions. Thank you for working on this!