fix bug when source would indefinitely append to table instead of updating it because of null value behavior in unique indices
This commit is contained in:
parent
996829b8e9
commit
af6f9d5db6
3 changed files with 7 additions and 12 deletions
|
|
@ -43,8 +43,7 @@ public class Crawler {
|
|||
UpdatableRecord<SourceRecord> source = new UpdatableRecordImpl<>(SOURCE);
|
||||
source.set(SOURCE.TYPE, item.type.getSqlName());
|
||||
source.set(SOURCE.ROOT_NAME, item.rootCategory);
|
||||
source.set(SOURCE.URL, item.url);
|
||||
source.set(SOURCE.PATH, item.path);
|
||||
source.set(SOURCE.URL_OR_PATH, item.url != null ? item.url : item.path);
|
||||
source.set(SOURCE.COOKIES, item.cookies);
|
||||
|
||||
sources.add(source);
|
||||
|
|
@ -144,7 +143,7 @@ public class Crawler {
|
|||
switch (source.type) {
|
||||
case "m3u-local" -> {
|
||||
try {
|
||||
if (source.path == null) {
|
||||
if (source.urlOrPath == null) {
|
||||
logger.error("m3u local has to have \"path\" variable");
|
||||
continue;
|
||||
} else if (source.rootName == null) {
|
||||
|
|
@ -152,7 +151,7 @@ public class Crawler {
|
|||
continue;
|
||||
}
|
||||
|
||||
String m3uData = Files.readString(Paths.get(source.path), StandardCharsets.UTF_8);
|
||||
String m3uData = Files.readString(Paths.get(source.urlOrPath), StandardCharsets.UTF_8);
|
||||
ArrayList<M3U> m3u = M3UParser.parse(m3uData);
|
||||
|
||||
updateAllChannels(m3u, source.rootName);
|
||||
|
|
|
|||
|
|
@ -12,11 +12,8 @@ public class Source {
|
|||
@Column(name = "ROOT_NAME")
|
||||
public String rootName;
|
||||
|
||||
@Column(name = "URL")
|
||||
public String url;
|
||||
|
||||
@Column(name = "PATH")
|
||||
public String path;
|
||||
@Column(name = "URL_OR_PATH")
|
||||
public String urlOrPath;
|
||||
|
||||
@Column(name = "COOKIES")
|
||||
public String cookies;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ CREATE TABLE source (
|
|||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type TEXT NOT NULL,
|
||||
root_name TEXT NOT NULL,
|
||||
url TEXT,
|
||||
path TEXT,
|
||||
url_or_path TEXT NOT NULL,
|
||||
cookies TEXT
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_source_url_path ON source(url,path);
|
||||
CREATE UNIQUE INDEX idx_source_url_or_path ON source(url_or_path);
|
||||
|
||||
CREATE TABLE crawl (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue