diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 15c458a9..06b2f49b 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -272,7 +272,7 @@ class Club extends RowModel return false; } - return $query; + return $query->group("follower"); } function getFollowersCount(): int diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index b4f8b4c6..b743793f 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -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 diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 348631e4..d132e015 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -39,11 +39,14 @@ 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; } } diff --git a/Web/Models/sql/get-followers.tsql b/Web/Models/sql/get-followers.tsql index ae23d63a..552aafb8 100644 --- a/Web/Models/sql/get-followers.tsql +++ b/Web/Models/sql/get-followers.tsql @@ -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 diff --git a/Web/Models/sql/get-friends.tsql b/Web/Models/sql/get-friends.tsql index dc7b0730..4831c968 100644 --- a/Web/Models/sql/get-friends.tsql +++ b/Web/Models/sql/get-friends.tsql @@ -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 diff --git a/Web/Models/sql/get-online-friends.tsql b/Web/Models/sql/get-online-friends.tsql index ad646554..7e81c621 100755 --- a/Web/Models/sql/get-online-friends.tsql +++ b/Web/Models/sql/get-online-friends.tsql @@ -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 diff --git a/Web/Models/sql/get-subscriptions-user.tsql b/Web/Models/sql/get-subscriptions-user.tsql index 722db194..ecf8ad79 100644 --- a/Web/Models/sql/get-subscriptions-user.tsql +++ b/Web/Models/sql/get-subscriptions-user.tsql @@ -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