Browse Source

[ENTITY][Actor][COMPONENT][Tag] Add `Actor->getNoteTags(?string $note_type)` which gets a cached list of NoteTags for notes of type $note_type for the actor

experimental
Hugo Sales 8 months ago
parent
commit
ca9945a4be
Signed by: someonewithpc <hugo@hsal.es> GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 41 additions and 2 deletions
  1. +30
    -1
      components/Tag/Tag.php
  2. +11
    -1
      src/Entity/Actor.php

+ 30
- 1
components/Tag/Tag.php View File

@@ -72,7 +72,7 @@ class Tag extends Component
if (!self::validate($tag)) {
return null; // Ignore invalid tag candidates
}
$canonical_tag = self::canonicalTag($tag, \is_null($lang_id) ? null : Language::getById($lang_id)->getLocale());
$canonical_tag = self::canonicalTag($tag, \is_null($lang_id) ? null : Language::getById($lang_id)->getLocale());
DB::persist($note_tag = NoteTag::create([
'tag' => $tag,
'canonical' => $canonical_tag,
@@ -86,6 +86,35 @@ class Tag extends Component
return $note_tag;
}

/**
* @return NoteTag[]
*/
public static function getNoteTags(int $actor_id, ?string $note_type): array
{
$query = <<<'EOF'
select nt from \App\Entity\Note n
join \Component\Tag\Entity\NoteTag nt with n.id = nt.note_id
where n.actor_id = :id
EOF;
if (\is_null($note_type)) {
return Cache::getList(
Actor::cacheKeys($actor_id, 'any')['note-tags'],
fn () => DB::dql(
$query,
['id' => $actor_id],
),
);
} else {
return Cache::getList(
Actor::cacheKeys($actor_id, $note_type)['note-tags'],
fn () => DB::dql(
$query . ' and n.type = :type',
['id' => $actor_id, 'type' => $note_type],
),
);
}
}

/**
* Process note by extracting any tags present
*/


+ 11
- 1
src/Entity/Actor.php View File

@@ -42,6 +42,7 @@ use Component\Group\Entity\LocalGroup;
use Component\Language\Entity\ActorLanguage;
use Component\Language\Entity\Language;
use Component\Subscription\Entity\ActorSubscription;
use Component\Tag\Tag;
use Functional as F;

/**
@@ -263,7 +264,8 @@ class Actor extends Entity
'id' => "actor-id-{$actor_id}",
'nickname' => "actor-nickname-id-{$actor_id}",
'fullname' => "actor-fullname-id-{$actor_id}",
'self-tags' => "actor-self-tags-{$actor_id}",
'self-tags' => "actor-self-tags-{$actor_id}",
'note-tags' => "actor-note-tags-{$actor_id}-{$other}", // $other is note type
'circles' => "actor-circles-{$actor_id}",
'subscribers' => "subscribers-{$actor_id}",
'subscribed' => "subscribed-{$actor_id}",
@@ -347,6 +349,14 @@ class Actor extends Entity
);
}

/**
* @return NoteTag[]
*/
public function getNoteTags(?string $note_type = null): array
{
return Tag::getNoteTags($this->getId(), $note_type);
}

private function getSubCount(string $which, string $column): int
{
return Cache::get(


Loading…
Cancel
Save