mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(api): chunk guild permission batch RPC over 100 guilds (#2829)
This commit is contained in:
@@ -36,6 +36,7 @@ import type {GuildResponse} from '@fluxer/schema/src/domains/guild/GuildResponse
|
|||||||
import {ms} from 'itty-time';
|
import {ms} from 'itty-time';
|
||||||
|
|
||||||
const PUSH_BADGE_COUNT_BATCH_SIZE = 100;
|
const PUSH_BADGE_COUNT_BATCH_SIZE = 100;
|
||||||
|
const USER_PERMISSIONS_BATCH_SIZE = 100;
|
||||||
|
|
||||||
const GATEWAY_ERROR_TO_DOMAIN_ERROR: Record<string, () => Error> = {
|
const GATEWAY_ERROR_TO_DOMAIN_ERROR: Record<string, () => Error> = {
|
||||||
[GatewayRpcMethodErrorCodes.GUILD_NOT_FOUND]: () => new UnknownGuildError(),
|
[GatewayRpcMethodErrorCodes.GUILD_NOT_FOUND]: () => new UnknownGuildError(),
|
||||||
@@ -1089,19 +1090,29 @@ export class GatewayService {
|
|||||||
if (guildIds.length === 0) {
|
if (guildIds.length === 0) {
|
||||||
return permissionsMap;
|
return permissionsMap;
|
||||||
}
|
}
|
||||||
const result = await this.call<{
|
const batches: Array<Array<GuildID>> = [];
|
||||||
permissions: Array<{
|
for (let index = 0; index < guildIds.length; index += USER_PERMISSIONS_BATCH_SIZE) {
|
||||||
guild_id: string;
|
batches.push(guildIds.slice(index, index + USER_PERMISSIONS_BATCH_SIZE));
|
||||||
permissions: string;
|
}
|
||||||
}>;
|
const results = await Promise.all(
|
||||||
}>('guild.get_user_permissions_batch', {
|
batches.map((batch) =>
|
||||||
guild_ids: guildIds.map((id) => id.toString()),
|
this.call<{
|
||||||
user_id: userId.toString(),
|
permissions: Array<{
|
||||||
channel_id: channelId ? channelId.toString() : '0',
|
guild_id: string;
|
||||||
});
|
permissions: string;
|
||||||
for (const item of result.permissions) {
|
}>;
|
||||||
const guildId = BigInt(item.guild_id) as GuildID;
|
}>('guild.get_user_permissions_batch', {
|
||||||
permissionsMap.set(guildId, BigInt(item.permissions));
|
guild_ids: batch.map((id) => id.toString()),
|
||||||
|
user_id: userId.toString(),
|
||||||
|
channel_id: channelId ? channelId.toString() : '0',
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
for (const result of results) {
|
||||||
|
for (const item of result.permissions) {
|
||||||
|
const guildId = BigInt(item.guild_id) as GuildID;
|
||||||
|
permissionsMap.set(guildId, BigInt(item.permissions));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return permissionsMap;
|
return permissionsMap;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user