|
|
|
@@ -22,6 +22,7 @@ import nu.marginalia.search.model.NavbarModel;
|
|
|
|
|
import nu.marginalia.search.model.ResultsPage;
|
|
|
|
|
import nu.marginalia.search.model.UrlDetails;
|
|
|
|
|
import nu.marginalia.search.svc.SearchFlagSiteService.FlagSiteFormData;
|
|
|
|
|
import nu.marginalia.service.server.RateLimiter;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
@@ -47,6 +48,8 @@ public class SearchSiteInfoService {
|
|
|
|
|
private final HikariDataSource dataSource;
|
|
|
|
|
private final SearchSiteSubscriptionService searchSiteSubscriptions;
|
|
|
|
|
|
|
|
|
|
private final RateLimiter rateLimiter = RateLimiter.custom(60);
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
public SearchSiteInfoService(SearchOperator searchOperator,
|
|
|
|
|
DomainInfoClient domainInfoClient,
|
|
|
|
@@ -238,6 +241,7 @@ public class SearchSiteInfoService {
|
|
|
|
|
boolean hasScreenshot = screenshotService.hasScreenshot(domainId);
|
|
|
|
|
boolean isSubscribed = searchSiteSubscriptions.isSubscribed(context, domain);
|
|
|
|
|
|
|
|
|
|
boolean rateLimited = !rateLimiter.isAllowed();
|
|
|
|
|
if (domainId < 0) {
|
|
|
|
|
domainInfoFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
|
|
|
|
similarSetFuture = CompletableFuture.failedFuture(new Exception("Unknown Domain ID"));
|
|
|
|
@@ -250,6 +254,12 @@ public class SearchSiteInfoService {
|
|
|
|
|
linkingDomainsFuture = CompletableFuture.failedFuture(new Exception("Assistant Service Unavailable"));
|
|
|
|
|
feedItemsFuture = CompletableFuture.failedFuture(new Exception("Assistant Service Unavailable"));
|
|
|
|
|
}
|
|
|
|
|
else if (rateLimited) {
|
|
|
|
|
domainInfoFuture = domainInfoClient.domainInformation(domainId);
|
|
|
|
|
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 {
|
|
|
|
|
domainInfoFuture = domainInfoClient.domainInformation(domainId);
|
|
|
|
|
similarSetFuture = domainInfoClient.similarDomains(domainId, 25);
|
|
|
|
@@ -257,7 +267,14 @@ public class SearchSiteInfoService {
|
|
|
|
|
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()) {
|
|
|
|
|
url = sampleResults.getFirst().url.withPathAndParam("/", null).toString();
|
|
|
|
|
}
|
|
|
|
@@ -276,8 +293,9 @@ public class SearchSiteInfoService {
|
|
|
|
|
sampleResults
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
requestMissingScreenshots(result);
|
|
|
|
|
|
|
|
|
|
if (!rateLimited) {
|
|
|
|
|
requestMissingScreenshots(result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|