@@ -41,7 +41,8 @@ class ilMDCopyrightSelectionEntry
4141 private string $ title = '' ;
4242 private string $ description = '' ;
4343 private string $ copyright = '' ;
44- private int $ usage = 0 ;
44+ // set null as initial value to trigger a query on demand
45+ private ?int $ usage = null ;
4546
4647 protected bool $ outdated = false ;
4748
@@ -187,6 +188,19 @@ public static function isEntry($a_cp_string): bool
187188
188189 public function getUsage (): int
189190 {
191+ // do a time-consuming usage count on demand
192+ if ($ this ->usage === null ) {
193+ $ query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
194+ "WHERE description = " . $ this ->db ->quote (
195+ 'il_copyright_entry__ ' . IL_INST_ID . '__ ' . $ this ->getEntryId (),
196+ 'text '
197+ );
198+
199+ $ res = $ this ->db ->query ($ query );
200+ $ row = $ this ->db ->fetchObject ($ res );
201+ $ this ->usage = (int ) $ row ->used ;
202+ }
203+
190204 return $ this ->usage ;
191205 }
192206
@@ -339,16 +353,6 @@ private function read(): void
339353 $ this ->setCopyright ($ rendered_cp );
340354 $ this ->setOutdated ($ entry ->isOutdated ());
341355 $ this ->setOrderPosition ($ entry ->position ());
342-
343- $ query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
344- "WHERE description = " . $ this ->db ->quote (
345- 'il_copyright_entry__ ' . IL_INST_ID . '__ ' . $ this ->getEntryId (),
346- 'text '
347- );
348-
349- $ res = $ this ->db ->query ($ query );
350- $ row = $ this ->db ->fetchObject ($ res );
351- $ this ->usage = (int ) $ row ->used ;
352356 }
353357
354358 public static function createIdentifier (int $ a_entry_id ): string
0 commit comments