diff --git a/src/Entity/Language.php b/src/Entity/Language.php index 288ed24118..4bce24917f 100644 --- a/src/Entity/Language.php +++ b/src/Entity/Language.php @@ -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 { $langs = Cache::getHashMap( diff --git a/src/Entity/NoteTag.php b/src/Entity/NoteTag.php index 9fd2575dd2..5373b0a1c2 100644 --- a/src/Entity/NoteTag.php +++ b/src/Entity/NoteTag.php @@ -110,9 +110,17 @@ class NoteTag extends Entity // @codeCoverageIgnoreEnd // }}} 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 { - 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