Skip to content

Commit 916844b

Browse files
authored
Merge pull request #17 from itk-dev/feature/optimize-database-queries
Updated personalized view
2 parents 77973ef + f0a34a5 commit 916844b

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Nedenfor ses dato for release og beskrivelse af opgaver som er implementeret.
44

55
## [Under udvikling]
66

7+
* Optimerede database forespørgsler i personalized view'et.
8+
79
## [1.7.0] 2025-05-02
810

911
* Updaterer minimal php version

src/Controller/Controller.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,8 @@ public function render(): array {
105105
* @phpstan-return array<string, mixed>
106106
*/
107107
public function myFormErrors(): array {
108-
$webforms = $this->entityTypeManager->getStorage('webform')->loadMultiple();
109-
$jobIds = [];
110-
foreach ($webforms as $webform) {
111-
if ($webform->access('update')) {
112-
$formJobIds = $this->helper->getQueueJobIds($webform->id());
113-
array_push($jobIds, ...$formJobIds);
114-
}
115-
}
116-
117-
$jobIds = array_unique($jobIds);
118108
$view = Views::getView('os2forms_failed_jobs_personalized');
119109
$view->setDisplay('block_1');
120-
$view->setArguments([implode(',', $jobIds)]);
121110

122111
$view->execute();
123112
$renderedView = $view->render() ?? ['#markup' => $this->t('No failed jobs')];

src/Helper/Helper.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,23 @@ private function removeQueueSubmissionRelation(string $submissionId): void {
650650
}
651651
}
652652

653+
/**
654+
* Get all webforms with update access.
655+
*
656+
* @phpstan-return array<int, mixed>
657+
*
658+
* @throws \Exception
659+
*/
660+
public function getAllWebformsWithUpdateAccess(): array {
661+
$webforms = [];
662+
663+
foreach ($this->entityTypeManager->getStorage('webform')->loadMultiple() as $webform) {
664+
if ($webform->access('update')) {
665+
$webforms[] = $webform->id();
666+
}
667+
}
668+
669+
return $webforms;
670+
}
671+
653672
}

src/Plugin/views/filter/SubmissionExistsGlobalFilter.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,15 @@ public function query(): void {
5959
$query = $this->query;
6060
$table = array_key_first($query->tables);
6161

62-
$existsQuery = $this->connection->select('os2forms_failed_jobs_queue_submission_relation', 'o');
63-
$existsQuery->fields('o', ['job_id']);
64-
$jobIds = $existsQuery->execute()->fetchCol();
62+
$webformSubQuery = $this->connection->select('webform', 'w')
63+
->fields('w', ['webform_id'])
64+
->condition('w.webform_id', $this->helper->getAllWebformsWithUpdateAccess(), 'IN');
6565

66-
foreach ($jobIds as $job) {
67-
if ($this->helper->getSubmissionSerialIdFromJob($job) > 0) {
68-
$jobs[] = $job;
69-
}
70-
}
71-
if (empty($jobs)) {
72-
// The 'IN' operator requires a non empty array.
73-
$jobs = [0];
74-
}
66+
$jobIdsSubQuery = $this->connection->select('os2forms_failed_jobs_queue_submission_relation', 'r')
67+
->fields('r', ['job_id'])
68+
->condition('r.webform_id', $webformSubQuery, 'IN');
7569

76-
$query->addWhere($this->options['group'], $table . '.job_id', $jobs, 'IN');
70+
$query->addWhere($this->options['group'], $table . '.job_id', $jobIdsSubQuery, 'IN');
7771
}
7872

7973
}

0 commit comments

Comments
 (0)