#Any ideas how i would improve this snippet
1 messages · Page 1 of 1 (latest)
also to be more specific this line is the problem
msg_object = await theme_vote.fetch_message(msg[0])
You haven't shown any of your SQL queries, or what team_vote is. So it's impossible for anyone to know what is causing the time
ok srry
vote_values is a list
and here is the sql querry
vote_values = cursor.execute ( "SELECT * FROM theme_msgs WHERE For_Jam = ? ORDER BY Amount_Votes DESC LIMIT 10", [jam]).fetchall()
jam is just a string
And what is theme_vote? Is it a text channel?
Eh whatever, doesn't really matter. Instead of looping over vote_values and waiting for fetch_message to complete in every iteration of the loop. You can use asyncio.gather to run multiple coroutines concurrently that will then return their values into a list.
Example
results = await asyncio.gather(some_coro(), another_coro())
print(results)
# ['Hello', 'world']
assuming some_coro returns 'Hello' and another_coro returns 'world'
Doing this should realistically cut your time down to ~0.33s
yes
well
0.33s isn't a huge time
as it takes apparently not 1 entire second
but 3 seconds
Either way it's going to be a lot faster to use gather
ok
And another thing you should do is try to use get_message first to see if the message is cached. If that returns None, use fetch_message
hmm oki dokie
but wait
msg_object = await theme_vote.fetch_message(msg[0]) needs to be executed first
so it can get without error msg_object.embeds[0].title
oh wait
im dumb its basically useless to do fetch
yeh i did optimise it
and runs better
no need for this