Исправление дублирования подписчиков/лайков/друзей (#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 $query;
return $query->group("follower");
}
function getFollowersCount(): int

View file

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

View file

@ -39,10 +39,13 @@ class User extends RowModel
$query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql");
$query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit );
$ids = [];
$rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
foreach($rels as $rel) {
$rel = (new Users)->get($rel->id);
if(!$rel) continue;
if(in_array($rel->getId(), $ids)) continue;
$ids[] = $rel->getId();
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
LEFT JOIN
(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
INNER JOIN
(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
INNER JOIN
(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
RIGHT JOIN
(SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1