mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-10-07 13:52:39 +02:00
Compare commits
6 Commits
deploy-025
...
deploy-025
Author | SHA1 | Date | |
---|---|---|---|
|
470b866008 | ||
|
4895a2ac7a | ||
|
fd32ae9fa7 | ||
|
470651ea4c | ||
|
8d4829e783 | ||
|
1290bc15dc |
@@ -112,7 +112,7 @@ public class HttpClientProvider implements Provider<HttpClient> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final RequestConfig defaultRequestConfig = RequestConfig.custom()
|
final RequestConfig defaultRequestConfig = RequestConfig.custom()
|
||||||
.setCookieSpec(StandardCookieSpec.RELAXED)
|
.setCookieSpec(StandardCookieSpec.IGNORE)
|
||||||
.setResponseTimeout(10, TimeUnit.SECONDS)
|
.setResponseTimeout(10, TimeUnit.SECONDS)
|
||||||
.setConnectionRequestTimeout(5, TimeUnit.MINUTES)
|
.setConnectionRequestTimeout(5, TimeUnit.MINUTES)
|
||||||
.build();
|
.build();
|
||||||
|
@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.SocketException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
@@ -23,7 +24,8 @@ public class RetryStrategy implements HttpRequestRetryStrategy {
|
|||||||
case SocketTimeoutException ste -> false;
|
case SocketTimeoutException ste -> false;
|
||||||
case SSLException ssle -> false;
|
case SSLException ssle -> false;
|
||||||
case UnknownHostException uhe -> false;
|
case UnknownHostException uhe -> false;
|
||||||
case HttpHostConnectException ex -> executionCount <= 2; // Only retry once for connection errors
|
case HttpHostConnectException ex -> executionCount < 2;
|
||||||
|
case SocketException ex -> executionCount < 2;
|
||||||
default -> executionCount <= 3;
|
default -> executionCount <= 3;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import nu.marginalia.search.model.NavbarModel;
|
|||||||
import nu.marginalia.search.model.ResultsPage;
|
import nu.marginalia.search.model.ResultsPage;
|
||||||
import nu.marginalia.search.model.UrlDetails;
|
import nu.marginalia.search.model.UrlDetails;
|
||||||
import nu.marginalia.search.svc.SearchFlagSiteService.FlagSiteFormData;
|
import nu.marginalia.search.svc.SearchFlagSiteService.FlagSiteFormData;
|
||||||
|
import nu.marginalia.service.server.RateLimiter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ public class SearchSiteInfoService {
|
|||||||
private final HikariDataSource dataSource;
|
private final HikariDataSource dataSource;
|
||||||
private final SearchSiteSubscriptionService searchSiteSubscriptions;
|
private final SearchSiteSubscriptionService searchSiteSubscriptions;
|
||||||
|
|
||||||
|
private final RateLimiter rateLimiter = RateLimiter.custom(60);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SearchSiteInfoService(SearchOperator searchOperator,
|
public SearchSiteInfoService(SearchOperator searchOperator,
|
||||||
DomainInfoClient domainInfoClient,
|
DomainInfoClient domainInfoClient,
|
||||||
@@ -238,12 +241,19 @@ public class SearchSiteInfoService {
|
|||||||
boolean hasScreenshot = screenshotService.hasScreenshot(domainId);
|
boolean hasScreenshot = screenshotService.hasScreenshot(domainId);
|
||||||
boolean isSubscribed = searchSiteSubscriptions.isSubscribed(context, domain);
|
boolean isSubscribed = searchSiteSubscriptions.isSubscribed(context, domain);
|
||||||
|
|
||||||
|
boolean rateLimited = !rateLimiter.isAllowed();
|
||||||
if (domainId < 0) {
|
if (domainId < 0) {
|
||||||
domainInfoFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
domainInfoFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
||||||
similarSetFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
similarSetFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
||||||
linkingDomainsFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
linkingDomainsFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
||||||
feedItemsFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
feedItemsFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
||||||
}
|
}
|
||||||
|
else if (rateLimited) {
|
||||||
|
domainInfoFuture = CompletableFuture.failedFuture(new Exception("Rate limit exceeded"));
|
||||||
|
similarSetFuture = CompletableFuture.failedFuture(new Exception("Rate limit exceeded"));
|
||||||
|
linkingDomainsFuture = CompletableFuture.failedFuture(new Exception("Rate limit exceeded"));
|
||||||
|
feedItemsFuture = CompletableFuture.failedFuture(new Exception("Rate limit exceeded"));
|
||||||
|
}
|
||||||
else if (!domainInfoClient.isAccepting()) {
|
else if (!domainInfoClient.isAccepting()) {
|
||||||
domainInfoFuture = CompletableFuture.failedFuture(new Exception("Assistant Service Unavailable"));
|
domainInfoFuture = CompletableFuture.failedFuture(new Exception("Assistant Service Unavailable"));
|
||||||
similarSetFuture = CompletableFuture.failedFuture(new Exception("Assistant Service Unavailable"));
|
similarSetFuture = CompletableFuture.failedFuture(new Exception("Assistant Service Unavailable"));
|
||||||
@@ -257,7 +267,14 @@ public class SearchSiteInfoService {
|
|||||||
feedItemsFuture = feedsClient.getFeed(domainId);
|
feedItemsFuture = feedsClient.getFeed(domainId);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UrlDetails> sampleResults = searchOperator.doSiteSearch(domainName, domainId,5, 1).results;
|
List<UrlDetails> sampleResults;
|
||||||
|
if (rateLimited) {
|
||||||
|
sampleResults = List.of();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sampleResults = searchOperator.doSiteSearch(domainName, domainId, 5, 1).results;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sampleResults.isEmpty()) {
|
if (!sampleResults.isEmpty()) {
|
||||||
url = sampleResults.getFirst().url.withPathAndParam("/", null).toString();
|
url = sampleResults.getFirst().url.withPathAndParam("/", null).toString();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,11 @@
|
|||||||
|
@param String message
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head><meta charset="UTF-8">
|
||||||
|
<title>Unavailable</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>Service Overloaded</h1>
|
||||||
|
<p>${message}</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user