pg support: group_concat

This commit is contained in:
xiaomlove
2026-04-25 13:44:23 +07:00
parent 7d18a7f76a
commit 1372776ba1
3 changed files with 17 additions and 4 deletions
+1 -1
View File
@@ -199,7 +199,7 @@ class SeedBoxRepository extends BaseRepository
$size = 1000;
$page = 1;
$logPrefix = "isAllowed: $isAllowed->name, field: $field->name, page: $page, size: $size";
$selectRaw = sprintf("uid, group_concat(%s) as str", $field == IpAsnEnum::ASN ? 'asn' : 'ip');
$selectRaw = sprintf("uid, %s as str", NexusDB::groupConcatField($field == IpAsnEnum::ASN ? 'asn' : 'ip'));
while (true) {
$list = SeedBoxRecord::getValidQuery(TypeEnum::USER, $isAllowed, $field)
->selectRaw($selectRaw)
+4 -2
View File
@@ -511,8 +511,9 @@ class ToolRepository extends BaseRepository
$stickyPromotionExists = NexusDB::hasTable($stickyPromotionParticipatorsTable);
$claimTableExists = NexusDB::hasTable($claimTable);
$hitAndRunTableExists = NexusDB::hasTable($hitAndRunTable);
$idsField = NexusDB::groupConcatField('id');
while (true) {
$snatchRes = NexusDB::select("select userid, torrentid, group_concat(id) as ids from snatched group by userid, torrentid having(count(*)) > 1 limit $size");
$snatchRes = NexusDB::select("select userid, torrentid, $idsField as ids from snatched group by userid, torrentid having(count(*)) > 1 limit $size");
if (empty($snatchRes)) {
break;
}
@@ -542,8 +543,9 @@ class ToolRepository extends BaseRepository
public function removeDuplicatePeer()
{
$size = 2000;
$idsField = NexusDB::groupConcatField('id');
while (true) {
$results = NexusDB::select("select torrent, userid, group_concat(id) as ids from peers group by torrent, peer_id, userid having(count(*)) > 1 limit $size");
$results = NexusDB::select("select torrent, userid, $idsField as ids from peers group by torrent, peer_id, userid having(count(*)) > 1 limit $size");
if (empty($results)) {
do_log("[DELETE_DUPLICATED_PEERS], no data: ". last_query());
break;
+12 -1
View File
@@ -533,7 +533,7 @@ class NexusDB
}
}
public static function upsertField(array $uniqueFields, array $updateFields): string
public static function upsertField(array $uniqueFields, array $updateFields = []): string
{
if (self::isMysql()) {
$updates = [];
@@ -557,4 +557,15 @@ class NexusDB
}
}
public static function groupConcatField(string $field): string
{
if (self::isMysql()) {
return sprintf("group_concat(%s)", $field);
} elseif (self::isPgsql()) {
return sprintf("string_agg(%s::text, ',')", $field);
} else {
throw new \RuntimeException('Not supported database.');
}
}
}