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