mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-17 22:07:37 +08:00
pg support: group_concat
This commit is contained in:
@@ -199,7 +199,7 @@ class SeedBoxRepository extends BaseRepository
|
|||||||
$size = 1000;
|
$size = 1000;
|
||||||
$page = 1;
|
$page = 1;
|
||||||
$logPrefix = "isAllowed: $isAllowed->name, field: $field->name, page: $page, size: $size";
|
$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) {
|
while (true) {
|
||||||
$list = SeedBoxRecord::getValidQuery(TypeEnum::USER, $isAllowed, $field)
|
$list = SeedBoxRecord::getValidQuery(TypeEnum::USER, $isAllowed, $field)
|
||||||
->selectRaw($selectRaw)
|
->selectRaw($selectRaw)
|
||||||
|
|||||||
@@ -511,8 +511,9 @@ class ToolRepository extends BaseRepository
|
|||||||
$stickyPromotionExists = NexusDB::hasTable($stickyPromotionParticipatorsTable);
|
$stickyPromotionExists = NexusDB::hasTable($stickyPromotionParticipatorsTable);
|
||||||
$claimTableExists = NexusDB::hasTable($claimTable);
|
$claimTableExists = NexusDB::hasTable($claimTable);
|
||||||
$hitAndRunTableExists = NexusDB::hasTable($hitAndRunTable);
|
$hitAndRunTableExists = NexusDB::hasTable($hitAndRunTable);
|
||||||
|
$idsField = NexusDB::groupConcatField('id');
|
||||||
while (true) {
|
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)) {
|
if (empty($snatchRes)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -542,8 +543,9 @@ class ToolRepository extends BaseRepository
|
|||||||
public function removeDuplicatePeer()
|
public function removeDuplicatePeer()
|
||||||
{
|
{
|
||||||
$size = 2000;
|
$size = 2000;
|
||||||
|
$idsField = NexusDB::groupConcatField('id');
|
||||||
while (true) {
|
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)) {
|
if (empty($results)) {
|
||||||
do_log("[DELETE_DUPLICATED_PEERS], no data: ". last_query());
|
do_log("[DELETE_DUPLICATED_PEERS], no data: ". last_query());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -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()) {
|
if (self::isMysql()) {
|
||||||
$updates = [];
|
$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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user