Skip to content

Commit a75361d

Browse files
committed
Fix incorrect ban query
1 parent 147ea95 commit a75361d

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

database/login.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,15 @@ import (
1414
)
1515

1616
const (
17-
SearchUserBan = `WITH known_ng_device_ids AS (
18-
WITH RECURSIVE device_tree AS (
19-
SELECT unnest(ng_device_id) AS device_id
20-
FROM users
21-
WHERE ng_device_id && $2
22-
UNION
23-
SELECT unnest(ng_device_id)
24-
FROM users
25-
JOIN device_tree dt
26-
ON ng_device_id && array[dt.device_id]
27-
) SELECT array_agg(DISTINCT device_id) FROM device_tree
28-
)
29-
SELECT has_ban, ban_tos, ng_device_id, ban_reason
17+
SearchUserBan = `SELECT has_ban, ban_tos, ng_device_id, ban_reason
3018
FROM users
3119
WHERE has_ban = true
32-
AND (profile_id = $3
33-
OR (ng_device_id && (SELECT * FROM known_ng_device_ids)
34-
AND $1 != 67349608)
35-
OR last_ip_address = $4
36-
OR ($4 != '' AND last_ip_address = $5)
37-
OR $7 && csnum)
38-
AND (ban_expires IS NULL OR ban_expires > $6)
20+
AND (profile_id = $2
21+
OR (ng_device_id && (SELECT array_agg(the_id) FROM UNNEST($1::bigint[]) AS x(the_id) WHERE x.the_id != 67349608))
22+
OR last_ip_address = $3
23+
OR ($3 != '' AND last_ip_address = $4)
24+
OR $6 && csnum)
25+
AND (ban_expires IS NULL OR ban_expires > $5)
3926
ORDER BY ban_tos DESC LIMIT 1`
4027
)
4128

@@ -229,7 +216,7 @@ func LoginUserToGPCM(pool *pgxpool.Pool, ctx context.Context, userId uint64, gsb
229216
var banReason string
230217

231218
timeNow := time.Now()
232-
err = pool.QueryRow(ctx, SearchUserBan, ngDeviceId, user.NgDeviceId, user.ProfileId, ipAddress, *lastIPAddress, timeNow, user.Csnum).Scan(&banExists, &banTOS, &bannedDeviceIdList, &banReason)
219+
err = pool.QueryRow(ctx, SearchUserBan, user.NgDeviceId, user.ProfileId, ipAddress, *lastIPAddress, timeNow, user.Csnum).Scan(&banExists, &banTOS, &bannedDeviceIdList, &banReason)
233220

234221
if err != nil {
235222
if err != pgx.ErrNoRows {

0 commit comments

Comments
 (0)