(minor) Remove dead code.
This commit is contained in:
parent
283d2caa81
commit
a7cd490593
@ -1,64 +0,0 @@
|
||||
package nu.marginalia.linkdb;
|
||||
|
||||
import nu.marginalia.linkdb.model.UrlStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
|
||||
public class LinkdbStatusWriter {
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public LinkdbStatusWriter(Path outputFile) throws SQLException {
|
||||
String connStr = "jdbc:sqlite:" + outputFile.toString();
|
||||
connection = DriverManager.getConnection(connStr);
|
||||
|
||||
try (var stream = ClassLoader.getSystemResourceAsStream("db/linkdb-status.sql");
|
||||
var stmt = connection.createStatement()
|
||||
) {
|
||||
var sql = new String(stream.readAllBytes());
|
||||
stmt.executeUpdate(sql);
|
||||
|
||||
// Disable synchronous writing as this is a one-off operation with no recovery
|
||||
stmt.execute("PRAGMA synchronous = OFF");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(List<UrlStatus> statuses) throws SQLException {
|
||||
try (var stmt = connection.prepareStatement("""
|
||||
INSERT OR IGNORE INTO STATUS(ID, URL, STATUS, DESCRIPTION)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""")) {
|
||||
int count = 0;
|
||||
for (var status : statuses) {
|
||||
stmt.setLong(1, status.id());
|
||||
stmt.setString(2, status.url().toString());
|
||||
stmt.setString(3, status.status());
|
||||
if (status.description() == null) {
|
||||
stmt.setNull(4, Types.VARCHAR);
|
||||
} else {
|
||||
stmt.setString(4, status.description());
|
||||
}
|
||||
stmt.addBatch();
|
||||
if (++count > 1000) {
|
||||
count = 0;
|
||||
stmt.executeBatch();
|
||||
}
|
||||
}
|
||||
if (count != 0) {
|
||||
stmt.executeBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
connection.close();
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package nu.marginalia.linkdb.model;
|
||||
|
||||
public enum UrlProtocol {
|
||||
HTTP,
|
||||
HTTPS;
|
||||
|
||||
public static int encode(String str) {
|
||||
if ("http".equalsIgnoreCase(str)) {
|
||||
return HTTP.ordinal();
|
||||
}
|
||||
else if ("https".equalsIgnoreCase(str)) {
|
||||
return HTTPS.ordinal();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(str);
|
||||
}
|
||||
|
||||
public static String decode(int ordinal) {
|
||||
return switch (values()[ordinal]) {
|
||||
case HTTP -> "http";
|
||||
case HTTPS -> "https";
|
||||
};
|
||||
};
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package nu.marginalia.linkdb.model;
|
||||
|
||||
import nu.marginalia.model.EdgeUrl;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public record UrlStatus(long id, EdgeUrl url, String status, @Nullable String description) {
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
CREATE TABLE STATUS (
|
||||
ID INT8 PRIMARY KEY,
|
||||
URL TEXT,
|
||||
STATUS TEXT NOT NULL,
|
||||
DESCRIPTION TEXT
|
||||
);
|
@ -1,33 +0,0 @@
|
||||
package nu.marginalia.linkdb;
|
||||
|
||||
import nu.marginalia.linkdb.model.UrlStatus;
|
||||
import nu.marginalia.model.EdgeUrl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class LinkdbStatusWriterTest {
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
Path tempPath = Files.createTempFile("linkdb-status", ".db");
|
||||
try {
|
||||
var writer = new LinkdbStatusWriter(tempPath);
|
||||
writer.add(List.of(
|
||||
new UrlStatus(5, new EdgeUrl("https://www.marginalia.nu/x"), "y", null),
|
||||
new UrlStatus(6, new EdgeUrl("https://www.marginalia.nu/y"), "y", "z")
|
||||
));
|
||||
writer.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
Files.deleteIfExists(tempPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import nu.marginalia.LanguageModels;
|
||||
import nu.marginalia.WmsaHome;
|
||||
import nu.marginalia.IndexLocations;
|
||||
import nu.marginalia.storage.FileStorageService;
|
||||
import nu.marginalia.linkdb.LinkdbStatusWriter;
|
||||
import nu.marginalia.linkdb.LinkdbWriter;
|
||||
import nu.marginalia.model.gson.GsonFactory;
|
||||
import nu.marginalia.service.SearchServiceDescriptors;
|
||||
@ -45,16 +44,6 @@ public class LoaderModule extends AbstractModule {
|
||||
return new LinkdbWriter(dbPath);
|
||||
}
|
||||
|
||||
@Inject @Provides @Singleton
|
||||
private LinkdbStatusWriter createLinkdbStatusWriter(FileStorageService service) throws SQLException, IOException {
|
||||
Path dbPath = IndexLocations.getLinkdbWritePath(service).resolve("urlstatus.db");
|
||||
|
||||
if (Files.exists(dbPath)) {
|
||||
Files.delete(dbPath);
|
||||
}
|
||||
return new LinkdbStatusWriter(dbPath);
|
||||
}
|
||||
|
||||
private Gson createGson() {
|
||||
return GsonFactory.get();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user