mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 13:09:00 +00:00
(assistant) Refactor scheduling of tasks within SimilarDomainsService
Changed the scheduling function to use a single schedule call instead of a fixed delay for the init task. The updateScreenshotInfo method was also moved and slightly refactored for clearer readability and consistency.
This commit is contained in:
parent
fed33ed64a
commit
ccf6b7caf3
@ -53,33 +53,12 @@ public class SimilarDomainsService {
|
||||
|
||||
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
service.scheduleWithFixedDelay(this::init, 0, 1, TimeUnit.SECONDS);
|
||||
service.schedule(this::init, 1, TimeUnit.SECONDS);
|
||||
|
||||
// Update screenshot info every hour
|
||||
service.scheduleAtFixedRate(this::updateScreenshotInfo, 1, 1, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
private void updateScreenshotInfo() {
|
||||
try (var connection = dataSource.getConnection()) {
|
||||
try (var stmt = connection.createStatement()) {
|
||||
var rs = stmt.executeQuery("""
|
||||
SELECT EC_DOMAIN.ID
|
||||
FROM EC_DOMAIN INNER JOIN DATA_DOMAIN_SCREENSHOT AS SCREENSHOT ON EC_DOMAIN.DOMAIN_NAME = SCREENSHOT.DOMAIN_NAME
|
||||
""");
|
||||
|
||||
while (rs.next()) {
|
||||
final int id = rs.getInt(1);
|
||||
final int idx = domainIdToIdx.get(id);
|
||||
|
||||
screenshotDomains.add(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException throwables) {
|
||||
logger.warn("Failed to update screenshot info", throwables);
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
logger.info("Loading similar domains data... ");
|
||||
@ -177,6 +156,27 @@ public class SimilarDomainsService {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateScreenshotInfo() {
|
||||
try (var connection = dataSource.getConnection()) {
|
||||
try (var stmt = connection.createStatement()) {
|
||||
var rs = stmt.executeQuery("""
|
||||
SELECT EC_DOMAIN.ID
|
||||
FROM EC_DOMAIN INNER JOIN DATA_DOMAIN_SCREENSHOT AS SCREENSHOT ON EC_DOMAIN.DOMAIN_NAME = SCREENSHOT.DOMAIN_NAME
|
||||
""");
|
||||
|
||||
while (rs.next()) {
|
||||
final int id = rs.getInt(1);
|
||||
final int idx = domainIdToIdx.get(id);
|
||||
|
||||
screenshotDomains.add(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException throwables) {
|
||||
logger.warn("Failed to update screenshot info", throwables);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return isReady;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user