(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.
This commit is contained in:
Viktor Lofgren 2025-01-01 16:29:01 +01:00
parent 0c839453c5
commit ab5c30ad51
3 changed files with 14 additions and 3 deletions

View File

@ -28,7 +28,7 @@ public class DbDomainQueries {
} }
public Integer getDomainId(EdgeDomain domain) { public Integer getDomainId(EdgeDomain domain) throws NoSuchElementException {
try (var connection = dataSource.getConnection()) { try (var connection = dataSource.getConnection()) {
return domainIdCache.get(domain, () -> { return domainIdCache.get(domain, () -> {
@ -42,6 +42,9 @@ public class DbDomainQueries {
throw new NoSuchElementException(); throw new NoSuchElementException();
}); });
} }
catch (UncheckedExecutionException ex) {
throw new NoSuchElementException();
}
catch (ExecutionException ex) { catch (ExecutionException ex) {
throw new RuntimeException(ex.getCause()); throw new RuntimeException(ex.getCause());
} }

View File

@ -14,6 +14,7 @@ import java.nio.IntBuffer;
import java.time.Duration; import java.time.Duration;
import java.util.Base64; import java.util.Base64;
import java.util.HashSet; import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
public class SearchSiteSubscriptionService { public class SearchSiteSubscriptionService {
@ -65,9 +66,14 @@ public class SearchSiteSubscriptionService {
} }
public boolean isSubscribed(Context context, EdgeDomain domain) { 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) { public void toggleSubscription(Context context, EdgeDomain domain) {

View File

@ -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.</p> 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.</p>
</div> </div>
@if (!model.domains().isEmpty())
<div class="border dark:border-gray-600 rounded md:my-4 overflow-hidden w-full md:w-auto"> <div class="border dark:border-gray-600 rounded md:my-4 overflow-hidden w-full md:w-auto">
<div class="bg-margeblue text-white p-2 text-sm">Recently Discovered Domains</div> <div class="bg-margeblue text-white p-2 text-sm">Recently Discovered Domains</div>
@ -73,6 +74,7 @@
</div> </div>
</div> </div>
@endif
</div> </div>