Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy Loading #1046

Merged
merged 71 commits into from
Dec 2, 2019
Merged

Lazy Loading #1046

merged 71 commits into from
Dec 2, 2019

Conversation

MinnDevelopment
Copy link
Member

@MinnDevelopment MinnDevelopment commented Jul 7, 2019

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

Implementation for lazy loading of guild members. This will disable the member chunking performed when the guild is received and instead load members as they appear. This obviously removes a lot of information but can be very useful for large bots that see a lot of members which are never active.

The only information missing when creating a member from a presence update seems to be the join date, we could in theory just disable this caching during lazy loading. Currently I just set the join date to the guild creation time instead.

You can dynamically load the entire member cache for a guild or single members.

guild.retrieveMembers().thenRun(() -> {
    // use guild with members loaded
});

guild.retrieveMemberById(86699011792191488L).queue((member) -> {
    // use member loaded through either cache or http request
});

This also adds support for disabling guild_subscriptions which disables all guild subscriptions such as presence and typing events. When guild subscriptions are disabled the user cache becomes inconsistent as discord will not inform us of updates directly. However, we can update the cached users through message and voice state events and REST calls.
We disable the user cache completely in this case because there are no member update events so there is no way to make a working system of caching them. The only users that get cached are users who participate in voice channels.

Example

new JDABuilder(TOKEN)
    .setGuildSubscriptionsEnabled(false)
    .setChunkingFilter(ChunkingFilter.include(125227483518861312L, 81384788765712384L));

@MinnDevelopment MinnDevelopment added this to the v4 release milestone Jul 10, 2019
@MinnDevelopment MinnDevelopment marked this pull request as ready for review July 11, 2019 09:00
@MinnDevelopment MinnDevelopment added the status: freezer this is currently put on hold label Jul 11, 2019
@MinnDevelopment

This comment has been minimized.

@MinnDevelopment

This comment has been minimized.

@MinnDevelopment MinnDevelopment removed the status: freezer this is currently put on hold label Nov 24, 2019
@MinnDevelopment MinnDevelopment modified the milestones: Upcoming Release, v4.1.0 Nov 24, 2019
@MinnDevelopment MinnDevelopment requested review from DV8FromTheWorld and removed request for DV8FromTheWorld November 24, 2019 06:34
@MinnDevelopment MinnDevelopment merged commit caf7d20 into development Dec 2, 2019
@MinnDevelopment MinnDevelopment deleted the experimental/lazy-loading branch December 2, 2019 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: experimental type: semi-breaking this might change internals in a non-comptible way
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants