Skip to content

Commit

Permalink
Исправление дублирования подписчиков/лайков/друзей (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
n1rwana authored Aug 4, 2023
1 parent a2384cc commit 5c76b56
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Web/Models/Entities/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function getFollowersQuery(string $sort = "follower ASC"): GroupedSelection
return false;
}

return $query;
return $query->group("follower");
}

function getFollowersCount(): int
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/Entities/Postable.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function getLikesCount(): int
return sizeof(DB::i()->getContext()->table("likes")->where([
"model" => static::class,
"target" => $this->getRecord()->id,
]));
])->group("origin"));
}

# TODO add pagination
Expand Down
5 changes: 4 additions & 1 deletion Web/Models/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ protected function _abstractRelationGenerator(string $filename, int $page = 1, i
$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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/sql/get-followers.tsql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/sql/get-friends.tsql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/sql/get-online-friends.tsql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/sql/get-subscriptions-user.tsql
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5c76b56

Please sign in to comment.