Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 20fa848

Browse files
committed
Perf: load repositories with a unique query instead of many small queries
(cherry picked from commit c955991)
1 parent 2b0b685 commit 20fa848

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

core/src/plugins/conf.sql/class.sqlConfDriver.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,25 @@ public function repoToArray($repository)
196196
*/
197197
protected function initRepoArrayFromDbFetch($array){
198198
$repositories = array();
199-
foreach ($array as $repo_row) {
200-
if($this->sqlDriver["driver"] == "postgre"){
201-
dibi::query("SET bytea_output=escape");
202-
}
203-
$res_opts = dibi::query('SELECT * FROM [ajxp_repo_options] WHERE [uuid] = %s', $repo_row['uuid']);
204-
$opts = $res_opts->fetchPairs('name', 'val');
205-
$repo = $this->repoFromDb($repo_row, $opts);
206-
199+
if(!count($array)){
200+
return $repositories;
201+
}
202+
// Load all at once
203+
$ids = array();
204+
$allOpts = array();
205+
foreach($array as $row) {
206+
$ids[] = $row['uuid'];
207+
$allOpts[$row['uuid']] = array("ROW" => $row, "OPTIONS" => array());
208+
}
209+
if($this->sqlDriver["driver"] == "postgre"){
210+
dibi::query("SET bytea_output=escape");
211+
}
212+
$dbres = dibi::query("SELECT [uuid], [name], [val] FROM [ajxp_repo_options] WHERE [uuid] IN (%s)", $ids);
213+
foreach($dbres as $row){
214+
$allOpts[$row['uuid']]["OPTIONS"][$row['name']] = $row['val'];
215+
}
216+
foreach($allOpts as $repoId => $repoOptions){
217+
$repo = $this->repoFromDb($repoOptions["ROW"], $repoOptions["OPTIONS"]);
207218
$repositories[$repo->getUniqueId()] = $repo;
208219
}
209220
return $repositories;

0 commit comments

Comments
 (0)