Skip to content

Commit 8a8e8ec

Browse files
committed
Merge pull request #9597 from fneumann/fix9-mantis45131
[Metadata] performance issue with unnecessary query on il_meta_rights
1 parent 85ff577 commit 8a8e8ec

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

components/ILIAS/MetaData/classes/Settings/Copyright/class.ilMDCopyrightSelectionEntry.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class ilMDCopyrightSelectionEntry
4242
private string $title = '';
4343
private string $description = '';
4444
private string $copyright = '';
45-
private int $usage = 0;
45+
// set null as initial value to trigger a query on demand
46+
private ?int $usage = null;
4647

4748
protected bool $outdated = false;
4849

@@ -188,6 +189,19 @@ public static function isEntry($a_cp_string): bool
188189

189190
public function getUsage(): int
190191
{
192+
// do a time-consuming usage count on demand
193+
if ($this->usage === null) {
194+
$query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
195+
"WHERE description = " . $this->db->quote(
196+
'il_copyright_entry__' . IL_INST_ID . '__' . $this->getEntryId(),
197+
'text'
198+
);
199+
200+
$res = $this->db->query($query);
201+
$row = $this->db->fetchObject($res);
202+
$this->usage = (int) $row->used;
203+
}
204+
191205
return $this->usage;
192206
}
193207

@@ -340,16 +354,6 @@ private function read(): void
340354
$this->setCopyright($rendered_cp);
341355
$this->setOutdated($entry->isOutdated());
342356
$this->setOrderPosition($entry->position());
343-
344-
$query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
345-
"WHERE description = " . $this->db->quote(
346-
'il_copyright_entry__' . IL_INST_ID . '__' . $this->getEntryId(),
347-
'text'
348-
);
349-
350-
$res = $this->db->query($query);
351-
$row = $this->db->fetchObject($res);
352-
$this->usage = (int) $row->used;
353357
}
354358

355359
public static function createIdentifier(int $a_entry_id): string

0 commit comments

Comments
 (0)