Skip to content

Commit

Permalink
feat: refresh dynamic config if sufficiently old (#598)
Browse files Browse the repository at this point in the history
Co-authored-by: pajlada <[email protected]>
Co-authored-by: Felanbird <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2024
1 parent 025f82a commit 703a365
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

- Minor: Pull latest dynamic configuration if sufficiently old. (#598)
- Minor: Allow overwriting webhooks or item lists on config import, rather than merging. (#595)
- Minor: Allow specifying tag IDs to apply for new forum thread messages. (#599)
- Minor: Add herbiboar support to kill count notifier. (#602)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dinkplugin/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import javax.swing.SwingUtilities;
import java.io.IOException;
import java.lang.reflect.Type;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -104,6 +106,8 @@ public class SettingsManager {
private final ConfigManager configManager;
private final OkHttpClient httpClient;

private volatile Instant lastDynamicImport = null;

/**
* Check whether a username complies with the configured RSN filter list.
*
Expand Down Expand Up @@ -305,6 +309,12 @@ void onGameState(GameState oldState, GameState newState) {

return true;
});

// refresh dynamic config if it's been 3+ hours
var lastImport = lastDynamicImport;
if (lastImport != null && Duration.between(lastImport, Instant.now()).toHours() >= 3) {
importDynamicConfig(config.dynamicConfigUrl());
}
}

void onTick() {
Expand Down Expand Up @@ -417,6 +427,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) {
map.remove(DYNAMIC_IMPORT_CONFIG_KEY);

handleImport(map, true);
lastDynamicImport = Instant.now();
}

@Override
Expand Down

0 comments on commit 703a365

Please sign in to comment.