Skip to content

Commit

Permalink
Fix bug where lidarr cache doesn't cache artist names properly + make…
Browse files Browse the repository at this point in the history
… timeout configurable (#60)
  • Loading branch information
shayaantx authored Feb 28, 2022
1 parent 02e1eeb commit 09d4331
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ properties*
dependency-reduced-pom.xml
*.jar
*.db

*.zip
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ botdarr:
| MAX_DOWNLOADS_TO_SHOW | The max number of downloads to show. If you set this to any value less than or equal to 0, no downloads will show | yes | 20 |
| MAX_RESULTS_TO_SHOW | The max number of results to show per search command. If you set this to any value less than 0, the bot won't startup | yes | 20 |
| COMMAND_PREFIX | The command prefix (default is !). Any prefix is allowed (but I haven't tested every single prefix in every client) | yes | ! |
| STATUS_ENDPOINTS | Endpoints that can be used to return statuses via !status command. The endpoints are separated by a comma and each endpoint is in the following format - name:hostname:port | no | |
| STATUS_ENDPOINTS | Endpoints that can be used to return statuses via !status command. The endpoints are separated by a comma and each endpoint is in the following format - name:hostname:port | no | |
| TIMEOUT | The connection/read timeout value (in milliseconds) for all outbound requests | no | 5000 |
<br/>

## Usage
Expand Down
1 change: 1 addition & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if [ ! -e "$propertiesFile" ]; then
addConfiguration "max-downloads-to-show" "${MAX_DOWNLOADS_TO_SHOW:-20}" "${propertiesFile}"
addConfiguration "max-results-to-show" "${MAX_RESULTS_TO_SHOW:-20}" "${propertiesFile}"
addConfiguration "command-prefix" "${COMMAND_PREFIX:-!}" "${propertiesFile}"
addConfiguration "timeout" "${TIMEOUT:-5000}" "${propertiesFile}"
fi

exec "$@"
19 changes: 18 additions & 1 deletion src/main/java/com/botdarr/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public static List<StatusEndPoint> getStatusEndpoints() {
return statusEndPoints;
}

/**
* @return The connection/read timeouts for all outbound requests (in ms)
*/
public static int getTimeout() {
try {
return Integer.parseInt(Config.getProperty(Config.Constants.TIMEOUT));
} catch (NumberFormatException e) {
LOGGER.error("Error parsing timeout", e);
}
return 5000;
}

private static StatusEndPoint getDomain(String constant, String name) {
try {
URI uri = new URI(getProperty(constant));
Expand Down Expand Up @@ -343,7 +355,7 @@ public static final class Constants {
public static final String MAX_SHOW_REQUESTS_PER_USER = "max-show-requests-per-user";

/**
* TODO: doc
* The max of artist requests per user per configured threshold
*/
public static final String MAX_ARTIST_REQUESTS_PER_USER = "max-artist-requests-per-user";

Expand Down Expand Up @@ -376,6 +388,11 @@ public static final class Constants {
* The additional status endpoints to check
*/
public static final String STATUS_ENDPOINTS = "status-endpoints";

/**
* Connection/read timeouts for all outbound requests
*/
public static final String TIMEOUT = "timeout";
}

private static String propertiesPath = "config/properties";
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/botdarr/api/lidarr/LidarrCache.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.botdarr.api.lidarr;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -12,7 +13,7 @@ public boolean doesArtistExist(LidarrArtist content) {

public void addArtist(LidarrArtist artist) {
existingForeignArtistIdToArtist.put(artist.getForeignArtistId(), artist);
existingArtistNamesToIds.put(artist.getArtistName(), artist.getForeignArtistId());
existingArtistNamesToIds.put(artist.getArtistName().toLowerCase(), artist.getForeignArtistId());
}

public void addQualityProfile(LidarrQualityProfile lidarrQualityProfile) {
Expand Down Expand Up @@ -44,7 +45,7 @@ public void removeDeletedMetadataProfiles(List<String> addUpdatedProfiles) {
}

public void removeDeletedArtists(List<String> addUpdatedArtists) {
existingArtistNamesToIds.keySet().retainAll(addUpdatedArtists);
existingArtistNamesToIds.values().retainAll(addUpdatedArtists);
existingForeignArtistIdToArtist.keySet().retainAll(addUpdatedArtists);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean turnOnTimeouts() {
public static <T> T makeRequest(RequestHandler requestHandler, ResponseHandler<T> responseHandler) {
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (requestHandler.turnOnTimeouts()) {
int timeout = 5000;
int timeout = Config.getTimeout();
requestConfigBuilder.setConnectTimeout(timeout);
requestConfigBuilder.setSocketTimeout(timeout);
requestConfigBuilder.setConnectionRequestTimeout(timeout);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.2
5.2.3

0 comments on commit 09d4331

Please sign in to comment.