Skip to content

Conversation

@MaybeNetwork
Copy link
Contributor

Unfixes 1333

Feature Summary and Justification

Issue 1142 reported that User.moderator_subreddits would not return more than 100 subreddits, and this information was added to the documentation in 1145. The method was deprecated in 1148, with a note to use Redditor.moderated instead, and was removed in 1333.

I suspect that the report of the alleged limitation of User.moderator_subreddits was not correct, and may have just been the result of a misunderstanding of how ListingGenerator works. I tested the sister method of User.moderator_subreddits, User.subreddits, and found that it also returns only 100 subreddits if you call list(reddit.user.subreddits()). But that happens because ListingGenerators default value for limit is 100. If you call list(reddit.user.subreddits(limit=None)), the ListingGenerator does yield all of the subreddits that you are subscribed to, by retrieving batches of 100 subreddits at a time. From what I can find on Github, it's not clear if anyone tested what happens when you call moderator_subreddits with limit set to None before the method was removed. The subreddits/mine/where endpoints are documented under the same heading, so it's reasonable to think that they would all share the same limitations. I don't see anything in the initial commit or the last released version that suggests any kind of endpoint-specific limit.

Even if there were a limit of 100 subreddits returned, moderated is not an adequate replacement for moderator_subreddits for the vast majority of users. Moderator_subreddits loads the data that you would get by calling Reddit.info with sr_names set to the names of the subs you moderate, and moderator returns a much smaller amount of data. You would need to make additional calls to info, or filter calls to contributor_subreddits to get the same information, which is not very convenient. Moderator_subreddits also has the advantage of returning the user subreddit, which is not something that moderated does.

Moderator_subreddits, which returns a listing, may actually be more robust than moderated, which returns a ModeratedList. In certain circumstances, calls to moderated may fail altogether, because all of the subreddits are returned at once. For example, request_bot moderates almost 20,000 subreddits. When I tried to use moderated with a user-mode token, I got 5xx errors. With a userless token, I was served 12MB and 1MB responses when I set "accept-encoding" to identity and gzip/deflate respectively. There may be a cap to the number of subreddits returned by subreddits/mine/moderator, but since it returns batches of up to 100 results at a time, you should at least be able to retrieve the top n subreddits before a hypothetical cutoff.

References

@LilSpazJoekp
Copy link
Member

This seems like an edge case where the replacement method has issues fetching such a large list. I have personally tested it with AutoModerator in the past without issues other than a slight delay with the request, however this isn't working anymore. I don't know what changed (if anything) with the endpoint.

Would you be able to request the old endpoint for these edge cases?

@MaybeNetwork
Copy link
Contributor Author

MaybeNetwork commented Jul 21, 2021

This seems like an edge case where the replacement method has issues fetching such a large list. I have personally tested it with AutoModerator in the past without issues other than a slight delay with the request, however this isn't working anymore. I don't know what changed (if anything) with the endpoint.

Would you be able to request the old endpoint for these edge cases?

If you're asking about using the old endpoint on AutoModerator, then no. Sorry if this was confusing.

The "new" endpoint, used by Redditor.moderated, is user/{user}/moderated_subreddits/, which fetches a certain set of data about the subreddits that any given Redditor moderates. The "old" endpoint, used by User.moderator_subreddits,
is subreddits/mine/moderator/, which data about the subreddits that you, the authenticated user, moderate. You can use the "new" endpoint to get a subset of the data that the "old" endpoint returns, but you can't use the "old" endpoint to get information about another user. My point is that the "new" endpoint, which is useful in it's own right, isn't really suitable for doing the job that "old" one does.

While I was writing the pull request, I also discovered that Redditor.moderated sometimes fails in extreme cases. so I included a note about a possible workaround. Come to think of it, I should probably edit the note to add that subreddits returned in read-only ⊆ subreddits returned in regular mode. I could take out the note about Redditor.moderated if you think that the note merits it's own PR.

I just tried reddit.redditor('automoderator').moderated() and got 5xxs, but was successful with the same request when I switched to read-only mode. (Read-only mode has it's own problems, but that's a separate, upcoming prawcore PR.)

@MaybeNetwork MaybeNetwork force-pushed the moderator-subreddits branch from 86f7343 to da7fe29 Compare July 21, 2021 07:28
@LilSpazJoekp
Copy link
Member

That is really strange that it would behave differently in read-only mode. Also, I just realized I misread this PR. I thought you were replacing the underling endpoint with the old one.

Does moderated() still fail on AutoModerator and request_bot if you change the headers like you mentioned?

Copy link
Member

@LilSpazJoekp LilSpazJoekp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of things. Let's move the doc changes to contributor_subreddits and subreddits to a new PR please.

@MaybeNetwork
Copy link
Contributor Author

That is really strange that it would behave differently in read-only mode. Also, I just realized I misread this PR. I thought you were replacing the underling endpoint with the old one.

Does moderated() still fail on AutoModerator and request_bot if you change the headers like you mentioned?

From the error messages I got, I would guess that that the request fails in logged-in mode because they have to check if the account has access to each individual subreddit. In read-only mode, it knows that only public subreddits are viewable, so the request is processed faster.

moderated consistently fails on AutoModerated when logged in. It worked last night on AutoModerator when in read only mode, but it just failed when I tried now. So perhaps the time allotted for request processing depends on the current amount of server load. The answer might also involve caching.

@MaybeNetwork MaybeNetwork force-pushed the moderator-subreddits branch from da7fe29 to 2d1f611 Compare July 21, 2021 22:19
The methods `User.contributor_subreddits` and `User.subreddits` need to
use either an explicit limit or a limit of None in order to retrieve more than
100 subreddits.
Copy link
Member

@LilSpazJoekp LilSpazJoekp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'll get this merged in!

@LilSpazJoekp LilSpazJoekp merged commit a460e7e into praw-dev:master Jul 21, 2021
@LilSpazJoekp
Copy link
Member

LilSpazJoekp commented Jul 21, 2021

🎇 Thanks for this!

Would you mind joining the slack when you get a chance? We would like to talk to you a couple of things.🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants