Skip to content

Commit

Permalink
performance tweaks, quick hack to run as stateful set
Browse files Browse the repository at this point in the history
  • Loading branch information
AEnterprise committed Dec 19, 2022
1 parent 0a870a4 commit ad55700
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion GearBot/Cogs/Censor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def check_message(self, member, content, channel, message_id, edit, reply,
censor_emoji_message = await Configuration.get_var(member.guild.id, "CENSORING", "CENSOR_EMOJI_ONLY_MESSAGES")
content = content.replace('\\', '')

if Configuration.get_var(member.guild.id, "CENSORING", "IGNORE_IDS"):
if await Configuration.get_var(member.guild.id, "CENSORING", "IGNORE_IDS"):
content = re.sub(r'(<(?:@|#|@&|@!)[0-9]{15,20}>)', '', content)
content = re.sub(r'<a?:[^: \n]+:([0-9]{15,20})>', '', content)
content = re.sub(r"(https://(?:canary|ptb)?\.?discord(?:app)?.com/channels/\d{15,20}/\d{15,20}/\d{15,20})", '', content)
Expand Down
12 changes: 11 additions & 1 deletion GearBot/GearBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,17 @@ async def initialize(bot):
"shard_ids": [cluster * 2, (cluster * 2) + 1]
})

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

GearbotLogging.info(f"Ready to go, spinning up as instance {args['cluster'] + 1}/{args['shard_count']}")



Expand Down
6 changes: 3 additions & 3 deletions GearBot/Util/MessageUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

async def get_message_data(bot, message_id):
message = None
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 5 * 60).replace(tzinfo=datetime.timezone.utc):
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 1 * 60).replace(tzinfo=datetime.timezone.utc):
parts = await bot.redis_pool.hgetall(f"messages:{message_id}")
if len(parts) == 7:
reply = int(parts["reply"])
Expand All @@ -42,12 +42,12 @@ async def insert_message(bot, message, redis=True):
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)
if message_type is not None:
pipe.hmset_dict(f"messages:{message.id}", type=message_type)
pipe.expire(f"messages:{message.id}", 5*60+2)
pipe.expire(f"messages:{message.id}", 1*60)
await pipe.execute()
await DBUtils.insert_message(message)

async def update_message(bot, message_id, content, pinned):
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 5 * 60).replace(tzinfo=datetime.timezone.utc):
if not Object(message_id).created_at <= datetime.datetime.utcfromtimestamp(time.time() - 1 * 60).replace(tzinfo=datetime.timezone.utc):
pipe = bot.redis_pool.pipeline()
pipe.hmset_dict(f"messages:{message_id}", content=content)
pipe.hmset_dict(f"messages:{message_id}", pinned=(1 if pinned else 0))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ sentry-sdk==0.19.2
pytz==2020.4
pyseeyou==1.0.1
prometheus_client==0.8.0
asyncpg==0.22.0
asyncpg==0.27.0
emoji==0.6.0
kubernetes==12.0.1

0 comments on commit ad55700

Please sign in to comment.