From ab5c30ad5146cfe3ce259b2364eb1531dc7e646a Mon Sep 17 00:00:00 2001
From: Viktor Lofgren
Date: Wed, 1 Jan 2025 16:29:01 +0100
Subject: [PATCH] (search) Fix site info view for completely unknown domains
Also correct the DbDomainQueries.getDomainId so that it throws NoSuchElementException when domain id is missing, and not UncheckedExecutionException via Cache.
---
.../db/java/nu/marginalia/db/DbDomainQueries.java | 5 ++++-
.../search/svc/SearchSiteSubscriptionService.java | 10 ++++++++--
.../search-service/resources/jte/siteinfo/start.jte | 2 ++
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/code/common/db/java/nu/marginalia/db/DbDomainQueries.java b/code/common/db/java/nu/marginalia/db/DbDomainQueries.java
index bde0c196..4533de5f 100644
--- a/code/common/db/java/nu/marginalia/db/DbDomainQueries.java
+++ b/code/common/db/java/nu/marginalia/db/DbDomainQueries.java
@@ -28,7 +28,7 @@ public class DbDomainQueries {
}
- public Integer getDomainId(EdgeDomain domain) {
+ public Integer getDomainId(EdgeDomain domain) throws NoSuchElementException {
try (var connection = dataSource.getConnection()) {
return domainIdCache.get(domain, () -> {
@@ -42,6 +42,9 @@ public class DbDomainQueries {
throw new NoSuchElementException();
});
}
+ catch (UncheckedExecutionException ex) {
+ throw new NoSuchElementException();
+ }
catch (ExecutionException ex) {
throw new RuntimeException(ex.getCause());
}
diff --git a/code/services-application/search-service/java/nu/marginalia/search/svc/SearchSiteSubscriptionService.java b/code/services-application/search-service/java/nu/marginalia/search/svc/SearchSiteSubscriptionService.java
index a7143185..6bd9f8ad 100644
--- a/code/services-application/search-service/java/nu/marginalia/search/svc/SearchSiteSubscriptionService.java
+++ b/code/services-application/search-service/java/nu/marginalia/search/svc/SearchSiteSubscriptionService.java
@@ -14,6 +14,7 @@ import java.nio.IntBuffer;
import java.time.Duration;
import java.util.Base64;
import java.util.HashSet;
+import java.util.NoSuchElementException;
import java.util.Set;
public class SearchSiteSubscriptionService {
@@ -65,9 +66,14 @@ public class SearchSiteSubscriptionService {
}
public boolean isSubscribed(Context context, EdgeDomain domain) {
- int domainId = dbDomainQueries.getDomainId(domain);
+ try {
+ int domainId = dbDomainQueries.getDomainId(domain);
- return getSubscriptions(context).contains(domainId);
+ return getSubscriptions(context).contains(domainId);
+ }
+ catch (NoSuchElementException ex) {
+ return false;
+ }
}
public void toggleSubscription(Context context, EdgeDomain domain) {
diff --git a/code/services-application/search-service/resources/jte/siteinfo/start.jte b/code/services-application/search-service/resources/jte/siteinfo/start.jte
index 74b02f92..6fa313b3 100644
--- a/code/services-application/search-service/resources/jte/siteinfo/start.jte
+++ b/code/services-application/search-service/resources/jte/siteinfo/start.jte
@@ -44,6 +44,7 @@
marginalia search resources, instead reach out with an email, and we'll work out some way of exporting the data or creating a dedicated API instead.
+ @if (!model.domains().isEmpty())
Recently Discovered Domains
@@ -73,6 +74,7 @@
+ @endif