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

Allow more configuration on data caching #1042

Draft
wants to merge 14 commits into
base: development
Choose a base branch
from

Conversation

MinnDevelopment
Copy link
Member

Pull Request Etiquette

Changes

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

Closes Issue: NaN

Description

With these changes I introduce XData and MutableXData interfaces which can be used to provide XUpdateDigestEvent rather than atomic events for each changed property. These interfaces can be implemented by the library user and provided using a callback.

new JDABuilder(TOKEN)
    .setGuildDataProvider((id) -> new CustomGuildData());

We provide 2 implementations by default:

Name Description
LIGHT No data is stored, only default values (constants)
RICH Everything is stored

You could easily implement custom providers by extending the existing LIGHT configuration:

public class CustomGuildData extends LightGuildData {
    private String description = "";
    private String bannerId = null;
    private String iconId = null;

    @Override
    public CustomGuildData copy() {
        // ...
    }

    // implement getters and setters
}

Example using rich and having digest events enabled:

@Override
public void onGuildUpdateDigest(@Nonnull GuildUpdateDigestEvent event) {
    LOG.info("Received guild update digest for guild {}", event.getGuild().getName());
}

@Override
public void onGenericGuildUpdate(@Nonnull GenericGuildUpdateEvent event) {
    if (!(event instanceof GuildUpdateDigestEvent)) {
        LOG.info("Received atomic guild update ({}) for guild {}", event.getPropertyIdentifier(), event.getGuild().getName());
    }
}

Output:

13:29:01.931 JDA INFO   Received guild update digest for guild Testing Bacon
13:29:01.932 JDA INFO   Received atomic guild update (max_members) for guild Testing Bacon
13:29:01.933 JDA INFO   Received atomic guild update (region) for guild Testing Bacon
13:29:01.933 JDA INFO   Received atomic guild update (afk_timeout) for guild Testing Bacon
13:29:01.934 JDA INFO   Received atomic guild update (afk_channel) for guild Testing Bacon
13:29:01.934 JDA INFO   Received atomic guild update (system_channel) for guild Testing Bacon

This might offer some new ways to handle update events
and might also allow to enable a light mode
# Conflicts:
#	src/main/java/net/dv8tion/jda/internal/JDAImpl.java
@MinnDevelopment
Copy link
Member Author

I also want to add a flag to switch between either digest events or atomic events. That way we move more towards 1:1 mapping of the events rather than 1:N like we do currently.

@MinnDevelopment MinnDevelopment added this to Incomplete in v4 Jul 6, 2019
@MinnDevelopment
Copy link
Member Author

This is probably not needed when we allow lazy loading and disabling guild subscriptions.

@MinnDevelopment MinnDevelopment removed this from Incomplete in v4 Aug 8, 2019
@@ -85,13 +81,14 @@ public JDA getJDA()
@Override
public OffsetDateTime getTimeJoined()
{
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(joinDate), OFFSET);
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(data.getTimeBoosted()), OFFSET);
Copy link
Contributor

@mlnrDev mlnrDev Sep 3, 2019

Choose a reason for hiding this comment

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

Should be replaced with data.getTimeJoined() instead.

return this;
}

public MemberImpl setJoinDate(long joinDate)
{
this.joinDate = joinDate;
this.data.setTimeBoosted(joinDate);
Copy link
Contributor

@mlnrDev mlnrDev Sep 3, 2019

Choose a reason for hiding this comment

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

Should be replaced with this.data.setTimeJoined(joinDate) instead.

@MinnDevelopment MinnDevelopment modified the milestones: Upcoming Release, v4.2.0 Dec 24, 2019
@MinnDevelopment
Copy link
Member Author

MinnDevelopment commented Dec 26, 2019

I want to revisit this for 4.3.0. I also want to make an easy switch to use the LIGHT mode on all entities by default like: builder.setDefaultCachePolicy(CachePolicy.LIGHT) which makes it easier to opt-in on specific entities.

@MinnDevelopment MinnDevelopment added the status: freezer this is currently put on hold label Dec 26, 2019
# Conflicts:
#	src/main/java/net/dv8tion/jda/api/JDABuilder.java
#	src/main/java/net/dv8tion/jda/api/sharding/DefaultShardManager.java
#	src/main/java/net/dv8tion/jda/internal/JDAImpl.java
#	src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java
#	src/main/java/net/dv8tion/jda/internal/entities/MemberImpl.java
A lot of these configurations are unnecessary
@MinnDevelopment MinnDevelopment removed this from the v4.2.0 milestone Apr 25, 2020
@MinnDevelopment MinnDevelopment added this to the v4.3.0 milestone Aug 30, 2020
@MinnDevelopment MinnDevelopment removed this from the v4.3.0 milestone Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants