@@ -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