[ENTITY][NoteTag][Language] Add convinience cache getters

This commit is contained in:
Hugo Sales 2021-12-04 14:07:15 +00:00
parent a47a01abee
commit 4f669d4e01
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 14 additions and 1 deletions

View File

@ -126,6 +126,11 @@ class Language extends Entity
); );
} }
public static function getFromNote(Note $note): self
{
return self::getFromId($note->getLanguageId());
}
public static function getLanguageChoices(): array public static function getLanguageChoices(): array
{ {
$langs = Cache::getHashMap( $langs = Cache::getHashMap(

View File

@ -110,9 +110,17 @@ class NoteTag extends Entity
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
// }}} Autocode // }}} Autocode
public static function cacheKey(int|Note $note_id)
{
if (!\is_int($note_id)) {
$note_id = $note_id->getId();
}
return "note-tags-{$note_id}";
}
public static function getFromNoteId(int $note_id): array public static function getFromNoteId(int $note_id): array
{ {
return Cache::getList("note-tags-{$note_id}", fn () => DB::dql('select nt from note_tag nt join note n with n.id = nt.note_id where n.id = :id', ['id' => $note_id])); return Cache::getList(self::cacheKey($note_id), fn () => DB::dql('select nt from note_tag nt join note n with n.id = nt.note_id where n.id = :id', ['id' => $note_id]));
} }
public function getUrl(?Actor $actor = null): string public function getUrl(?Actor $actor = null): string