Исправление дублирования подписчиков/лайков/друзей (#941)

This commit is contained in:
n1rwana 2023-08-04 15:10:23 +03:00 committed by GitHub
parent a2384cc231
commit 5c76b56da4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 7 deletions

View file

@ -272,7 +272,7 @@ class Club extends RowModel
return false; return false;
} }
return $query; return $query->group("follower");
} }
function getFollowersCount(): int function getFollowersCount(): int

View file

@ -84,7 +84,7 @@ abstract class Postable extends Attachable
return sizeof(DB::i()->getContext()->table("likes")->where([ return sizeof(DB::i()->getContext()->table("likes")->where([
"model" => static::class, "model" => static::class,
"target" => $this->getRecord()->id, "target" => $this->getRecord()->id,
])); ])->group("origin"));
} }
# TODO add pagination # TODO add pagination

View file

@ -39,11 +39,14 @@ class User extends RowModel
$query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql"); $query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql");
$query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit ); $query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit );
$ids = [];
$rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id); $rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
foreach($rels as $rel) { foreach($rels as $rel) {
$rel = (new Users)->get($rel->id); $rel = (new Users)->get($rel->id);
if(!$rel) continue; if(!$rel) continue;
if(in_array($rel->getId(), $ids)) continue;
$ids[] = $rel->getId();
yield $rel; yield $rel;
} }
} }

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM (SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
LEFT JOIN LEFT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM (SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
INNER JOIN INNER JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT follower AS __id FROM (SELECT DISTINCT(follower) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
INNER JOIN INNER JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1

View file

@ -1,4 +1,4 @@
(SELECT target AS __id FROM (SELECT DISTINCT(target) AS __id FROM
(SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0
RIGHT JOIN RIGHT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1