bug PR-4.4-dev Pending

User tests: Successful: Unsuccessful:

avatar Denitz
Denitz
23 Feb 2022

Summary of Changes

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.

Testing Instructions

Test scheduled tasks

Actual result BEFORE applying this Pull Request

See two queries for #__scheduler_tasks table.

Expected result AFTER applying this Pull Request

See one query for #__scheduler_tasks table.
com_scheduler works as before.

Documentation Changes Required

No.

54d4f77 23 Feb 2022 avatar fix
avatar Denitz Denitz - open - 23 Feb 2022
avatar Denitz Denitz - change - 23 Feb 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 23 Feb 2022
Category Front End Plugins
82d9035 23 Feb 2022 avatar CS
avatar Denitz Denitz - change - 23 Feb 2022
Labels Added: ?
3235f0d 23 Feb 2022 avatar CS
avatar Denitz Denitz - change - 23 Feb 2022
The description was changed
avatar Denitz Denitz - edited - 23 Feb 2022
51c0b43 23 Feb 2022 avatar CS
cf09c88 1 Mar 2022 avatar fix
avatar ditsuke
ditsuke - comment - 26 Mar 2022

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!

avatar Denitz Denitz - change - 8 Jun 2022
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 8 Jun 2022
Category Front End Plugins Administration Front End Plugins
avatar HLeithner
HLeithner - comment - 27 Jun 2022

This pull request has automatically rebased to 4.2-dev.

avatar joomla-bot
joomla-bot - comment - 27 Jun 2022

This pull requests has been automatically converted to the PSR-12 coding standard.

avatar Denitz Denitz - change - 23 Jul 2022
Labels Added: ? ?
Removed: ? ?
avatar Denitz Denitz - change - 24 Mar 2023
Labels Removed: ?
avatar Denitz Denitz - change - 27 Mar 2023
Labels Added: PR-4.3-dev
Removed: ?
avatar obuisard obuisard - change - 2 Jun 2023
Title
Optimize scheduler running plugin
[4.4] Optimize scheduler running plugin
avatar obuisard obuisard - edited - 2 Jun 2023
avatar laoneo laoneo - change - 9 Jun 2023
Labels Added: bug
avatar laoneo
laoneo - comment - 9 Jun 2023

Can you fix the conflict?

avatar Denitz Denitz - change - 13 Jun 2023
Labels Added: PR-4.4-dev
Removed: PR-4.3-dev
avatar MacJoom
MacJoom - comment - 9 Aug 2023

@Denitz - thank you for your work - what about ditsukes comment, moving the query to the model - would be nice.

avatar Denitz
Denitz - comment - 10 Aug 2023

@MacJoom The query was moved to the model a year ago.

avatar MacJoom
MacJoom - comment - 10 Aug 2023

Sorry i missed that one

avatar MacJoom MacJoom - change - 11 Sep 2023
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2023-09-11 20:07:34
Closed_By MacJoom
avatar MacJoom MacJoom - close - 11 Sep 2023
avatar MacJoom MacJoom - merge - 11 Sep 2023

Add a Comment

Login with GitHub to post a comment