mirror of https://gitlab.com/litecord/litecord.git
gateway: add max_concurrency support
This commit is contained in:
parent
2f5f848442
commit
b468883e2e
|
|
@ -51,6 +51,14 @@ async def api_gateway_bot():
|
||||||
user_id,
|
user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
max_concurrency = await app.db.fetchval(
|
||||||
|
"""select max_concurrency
|
||||||
|
from users
|
||||||
|
where id = $1
|
||||||
|
""",
|
||||||
|
user_id,
|
||||||
|
)
|
||||||
|
|
||||||
shards = max(int(guild_count / 1000), 1)
|
shards = max(int(guild_count / 1000), 1)
|
||||||
|
|
||||||
# get _ws.session ratelimit
|
# get _ws.session ratelimit
|
||||||
|
|
@ -78,7 +86,7 @@ async def api_gateway_bot():
|
||||||
"total": bucket.requests,
|
"total": bucket.requests,
|
||||||
"remaining": bucket._tokens,
|
"remaining": bucket._tokens,
|
||||||
"reset_after": int(reset_after_ts * 1000),
|
"reset_after": int(reset_after_ts * 1000),
|
||||||
"max_concurrency": 1,
|
"max_concurrency": max_concurrency,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -811,7 +811,15 @@ class GatewayWebsocket:
|
||||||
except (Unauthorized, Forbidden):
|
except (Unauthorized, Forbidden):
|
||||||
raise WebsocketClose(4004, "Authentication failed")
|
raise WebsocketClose(4004, "Authentication failed")
|
||||||
|
|
||||||
await self._connect_ratelimit(user_id)
|
max_concurrency = await self.app.db.fetchval(
|
||||||
|
"""select max_concurrency
|
||||||
|
from users
|
||||||
|
where id = $1
|
||||||
|
""",
|
||||||
|
user_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
await self._connect_ratelimit(f"{str(user_id)}%{shard[0]%max_concurrency}")
|
||||||
|
|
||||||
bot = await self.app.db.fetchval(
|
bot = await self.app.db.fetchval(
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
alter table users
|
||||||
|
add column max_concurrency int not null default 1
|
||||||
|
check(bot = true or max_concurrency = 1);
|
||||||
Loading…
Reference in New Issue