Skip to content

Commit ad55700

Browse files
committed
performance tweaks, quick hack to run as stateful set
1 parent 0a870a4 commit ad55700

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

GearBot/Cogs/Censor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def check_message(self, member, content, channel, message_id, edit, reply,
7474
censor_emoji_message = await Configuration.get_var(member.guild.id, "CENSORING", "CENSOR_EMOJI_ONLY_MESSAGES")
7575
content = content.replace('\\', '')
7676

77-
if Configuration.get_var(member.guild.id, "CENSORING", "IGNORE_IDS"):
77+
if await Configuration.get_var(member.guild.id, "CENSORING", "IGNORE_IDS"):
7878
content = re.sub(r'(<(?:@|#|@&|@!)[0-9]{15,20}>)', '', content)
7979
content = re.sub(r'<a?:[^: \n]+:([0-9]{15,20})>', '', content)
8080
content = re.sub(r"(https://(?:canary|ptb)?\.?discord(?:app)?.com/channels/\d{15,20}/\d{15,20}/\d{15,20})", '', content)

GearBot/GearBot.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,17 @@ async def initialize(bot):
194194
"shard_ids": [cluster * 2, (cluster * 2) + 1]
195195
})
196196

197-
GearbotLogging.info(f"Ready to go, spinning up as instance {args['cluster'] + 1}/{args['shard_count']}")
197+
elif 'stateful' in os.environ:
198+
GearbotLogging.info(f"GearBot is deployed as stateful set, determining cluster id based on hostname {os.uname()[1]}")
199+
cluster = loop.run_until_complete(node_init(0, 0))
200+
num_clusters = int(os.environ["num_clusters"])
201+
args.update({
202+
"shard_count": num_clusters * 2,
203+
"cluster": cluster,
204+
"shard_ids": [cluster * 2, (cluster * 2) + 1]
205+
})
206+
207+
GearbotLogging.info(f"Ready to go, spinning up as instance {args['cluster'] + 1}/{args['shard_count']}")
198208

199209

200210

GearBot/Util/MessageUtils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
async def get_message_data(bot, message_id):
2121
message = None
22-
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 5 * 60).replace(tzinfo=datetime.timezone.utc):
22+
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 1 * 60).replace(tzinfo=datetime.timezone.utc):
2323
parts = await bot.redis_pool.hgetall(f"messages:{message_id}")
2424
if len(parts) == 7:
2525
reply = int(parts["reply"])
@@ -42,12 +42,12 @@ async def insert_message(bot, message, redis=True):
4242
channel=message.channel.id, server=message.guild.id, pinned=1 if message.pinned else 0, attachments='|'.join((f"{str(a.id)}/{str(a.filename)}" for a in message.attachments)), reply=message.reference.message_id if is_reply else 0)
4343
if message_type is not None:
4444
pipe.hmset_dict(f"messages:{message.id}", type=message_type)
45-
pipe.expire(f"messages:{message.id}", 5*60+2)
45+
pipe.expire(f"messages:{message.id}", 1*60)
4646
await pipe.execute()
4747
await DBUtils.insert_message(message)
4848

4949
async def update_message(bot, message_id, content, pinned):
50-
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 5 * 60).replace(tzinfo=datetime.timezone.utc):
50+
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 1 * 60).replace(tzinfo=datetime.timezone.utc):
5151
pipe = bot.redis_pool.pipeline()
5252
pipe.hmset_dict(f"messages:{message_id}", content=content)
5353
pipe.hmset_dict(f"messages:{message_id}", pinned=(1 if pinned else 0))

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ sentry-sdk==0.19.2
77
pytz==2020.4
88
pyseeyou==1.0.1
99
prometheus_client==0.8.0
10-
asyncpg==0.22.0
10+
asyncpg==0.27.0
1111
emoji==0.6.0
1212
kubernetes==12.0.1

0 commit comments

Comments
 (0)