(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()) {
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());
}

View File

@ -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,10 +66,15 @@ public class SearchSiteSubscriptionService {
}
public boolean isSubscribed(Context context, EdgeDomain domain) {
try {
int domainId = dbDomainQueries.getDomainId(domain);
return getSubscriptions(context).contains(domainId);
}
catch (NoSuchElementException ex) {
return false;
}
}
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>
</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="bg-margeblue text-white p-2 text-sm">Recently Discovered Domains</div>
@ -73,6 +74,7 @@
</div>
</div>
@endif
</div>