From 025957e8b2d74f157b391c6b2ed875045a58060d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 16 Aug 2014 02:40:39 +0000 Subject: [PATCH] * fix efficiency issues --- BuildData.groovy | 17 +++++++++-------- .../net/filebot/cli/ScriptShellBaseClass.java | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/BuildData.groovy b/BuildData.groovy index 5ab6197c..aecf4d29 100644 --- a/BuildData.groovy +++ b/BuildData.groovy @@ -181,19 +181,21 @@ if (tvdb_txt.exists()) { } } -def tvdb_updates = [] +def tvdb_updates = [:] as TreeSet new File('updates_all.xml').eachLine('UTF-8'){ def m = (it =~ '(\\d+)') - while(m.find()) { - tvdb_updates << [id: m.group(1) as Integer, time: m.group(2) as Integer] + while(m.find()) { + def id = m.group(1) as Integer + def time = m.group(2) as Integer + tvdb_updates[id] = [id: id, time: time] } } -tvdb_updates.each{ update -> +tvdb_updates.values().each{ update -> if (tvdb[update.id] == null || update.time > tvdb[update.id][0]) { try { - retry(2, 5000) { + retry(2, 500) { def seriesNames = [] def xml = new XmlSlurper().parse("http://thetvdb.com/api/BA864DEE427E384A/series/${update.id}/en.xml") def imdbid = xml.Series.IMDB_ID.text() @@ -220,10 +222,10 @@ tvdb_updates.each{ update -> def data = [update.time, update.id, imdbid, rating ?: 0, votes ?: 0] + seriesNames.findAll{ it != null && it.length() > 0 } tvdb.put(update.id, data) println "Update $update => $data" - sleep(1000) } } catch(Throwable e) { + printException(e, false) def data = [update.time, update.id, '', 0, 0] tvdb.put(update.id, data) println "Update $update => $data" @@ -232,9 +234,8 @@ tvdb_updates.each{ update -> } // remove entries that have become invalid -def tvdb_ids = tvdb_updates.findResults{ it.id } as HashSet tvdb.keySet().toList().each{ id -> - if (!tvdb_ids.contains(id)) { + if (tvdb_updates[id] == null) { println "Invalid ID found: ${tvdb[id]}" tvdb.remove(id) } diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 239b63c8..19c37a95 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -125,6 +125,10 @@ public abstract class ScriptShellBaseClass extends Script { } } + public void printException(Throwable t) { + printException(t, false); + } + public void printException(Throwable t, boolean severe) { if (severe) { CLILogger.log(Level.SEVERE, String.format("%s: %s", t.getClass().getSimpleName(), t.getMessage()), StackTraceUtils.deepSanitize(t));