[ENTITY][Actor] Partition the results of the joint query into a separate list of ActorsCircles and ActorTags, as desired

This commit is contained in:
Hugo Sales 2021-11-30 22:08:40 +00:00 committed by Diogo Peralta Cordeiro
parent a3e5f7646c
commit 6c7f69dd94
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0

View File

@ -292,44 +292,49 @@ class Actor extends Entity
if (\is_null($scoped)) { if (\is_null($scoped)) {
return Cache::get( return Cache::get(
"othertags-{$this->getId()}", "othertags-{$this->getId()}",
fn () => (($t = DB::dql( fn () => F\partition(
<<< 'EOQ' DB::dql(
SELECT circle, tag <<< 'EOQ'
FROM actor_tag tag SELECT circle, tag
JOIN actor_circle circle FROM actor_tag tag
WITH tag.tagger = circle.tagger JOIN actor_circle circle
AND tag.tag = circle.tag WITH tag.tagger = circle.tagger
WHERE tag.tagged = :id AND tag.tag = circle.tag
ORDER BY tag.modified DESC, tag.tagged DESC WHERE tag.tagged = :id
EOQ, ORDER BY tag.modified DESC, tag.tagged DESC
['id' => $this->getId()], EOQ,
options: ['offset' => $offset, 'limit' => $limit], ['id' => $this->getId()],
)) === [] ? [[],[]] : $t), options: ['offset' => $offset, 'limit' => $limit],
),
fn ($o) => $o instanceof ActorCircle,
),
); );
} else { } else {
$scoped_id = \is_int($scoped) ? $scoped : $scoped->getId(); $scoped_id = \is_int($scoped) ? $scoped : $scoped->getId();
return Cache::get( return Cache::get(
"othertags-{$this->getId()}-by-{$scoped_id}", "othertags-{$this->getId()}-by-{$scoped_id}",
fn () => (($t = DB::dql( fn () => F\partition(
<<< 'EOQ' DB::dql(
SELECT circle, tag <<< 'EOQ'
FROM actor_tag tag SELECT circle, tag
JOIN actor_circle circle FROM actor_tag tag
WITH JOIN actor_circle circle
tag.tagger = circle.tagger WITH tag.tagger = circle.tagger
AND tag.tag = circle.tag AND tag.tag = circle.tag
WHERE WHERE
tag.tagged = :id tag.tagged = :id
AND (circle.private != true AND (circle.private != true
OR (circle.tagger = :scoped OR (circle.tagger = :scoped
AND circle.private = true AND circle.private = true
) )
) )
ORDER BY tag.modified DESC, tag.tagged DESC ORDER BY tag.modified DESC, tag.tagged DESC
EOQ, EOQ,
['id' => $this->getId(), 'scoped' => $scoped_id], ['id' => $this->getId(), 'scoped' => $scoped_id],
options: ['offset' => $offset, 'limit' => $limit], options: ['offset' => $offset, 'limit' => $limit],
)) === [] ? [[],[]] : $t), ),
fn ($o) => $o instanceof ActorCircle,
),
); );
} }
} }