Problem/Motivation

Database backend is getting current time for each of queued jobs but for no reason

Steps to reproduce

https://git.drupalcode.org/project/advancedqueue/-/blob/8.x-1.x/src/Plug...

Proposed resolution

\Drupal\advancedqueue\Plugin\AdvancedQueue\Backend\Database::enqueueJobs() should use pre-calculate "AvailableTime" for each job which missing job's override

Remaining tasks

review/commit

User interface changes

no

API changes

no

Data model changes

no

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
StatusFileSize
new895 bytes
andypost’s picture

Category: Feature request » Task
StatusFileSize
new1.03 KB
new1.9 KB

And here's a test

andypost’s picture

StatusFileSize
new1.94 KB
new2.19 KB

Extend testing and prevent recalculate when no jobs passed

jonathanshaw’s picture

Status: Needs review » Reviewed & tested by the community
bojanz’s picture

Status: Reviewed & tested by the community » Needs work

I dislike this fix, it's not readable and it takes time to understand.

There is no need to have the whole $available_time expression inside the setter call. Just define:

$available_time = $this->time->getCurrentTime() + $delay;

above the foreach, and then always use it in the if (i$job->getAvailableTime()).

I also don't think this change needs a test, since it is a performance optimization, not changed business logic.