PyDrocsid / cogs

The official cog library used by PyDrocsid bots
GNU General Public License v3.0
13 stars 5 forks source link

Be a little friendlier to the Reddit API #125

Closed Scriptim closed 1 year ago

Scriptim commented 3 years ago

Description

Issue This potentially resolves #124.

Additional Notes The number of requests can be further optimized in such a way that all posts are retrieved at once. In this case, the mapping to the correct Discord text channels would have to be done subsequently.

Regarding the settings for the cog, the following changes:

Tert0 commented 3 years ago

Note: Don’t create a session per request. Most likely you need a session per application which performs all requests altogether. More complex cases may require a session per site, e.g. one for Github and other one for Facebook APIs. Anyway making a session for every request is a very bad idea. A session contains a connection pool inside. Connection reusage and keep-alives (both are on by default) may speed up total performance.

https://docs.aiohttp.org/en/stable/client_quickstart.html

codeclimate[bot] commented 3 years ago

Code Climate has analyzed commit f0b2b777 and detected 0 issues on this pull request.

View more on Code Climate.

Scriptim commented 2 years ago

The limit changes its meaning from a per-subreddit limit to a per-textchannel limit.

Would it be possible to change that back? Or split the posts evenly between the subreddits, so that not x posts are taken from the first subreddit and the others are ignored?

It's not that straightforward. The new API calls fetch posts from multiple subreddits at once by having the subreddits joined together in the URL with a plus. See for example here. It is beyond our control how the posts are distributed among the different subreddits, though I guess the distribution is quite fair. In theory, you could rank the posts yourself again, so that they are evenly distributed. In this case, however, you would have to either query more posts than you actually want to send, or query posts repeatedly until you have gathered enough. In a way, this would defeat the purpose of this pull request. I don't think there is a reasonable solution to implement a per-subreddit limit without doing unnecessary API requests again. So I' d advocate leaving it at the per-textchannel limit.

Scriptim commented 2 years ago

Hey, jfyi: I will not continue to work on this pull request. If you have any change requests, you'll either have to implement them yourself or simply close the pull request (if I eventually get the impression that it's going stale, I'll close it on my own).