From 59160984cc7cbf8f44f2993ecadb0e8294a8e551 Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 3 Jul 2014 13:06:29 +0200 Subject: [PATCH] timeline performance update --- htroot/api/timeline_p.java | 3 +++ .../net/yacy/search/query/AccessTracker.java | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/htroot/api/timeline_p.java b/htroot/api/timeline_p.java index a22bac185..e25180b45 100644 --- a/htroot/api/timeline_p.java +++ b/htroot/api/timeline_p.java @@ -76,6 +76,9 @@ public final class timeline_p { try {fromDate = GenericFormatter.SHORT_SECOND_FORMATTER.parse(post.get("from", "20031215182700"));} catch (ParseException e) {} try {toDate = GenericFormatter.SHORT_SECOND_FORMATTER.parse(post.get("to", GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date())));} catch (ParseException e) {} + // get latest dump; + AccessTracker.dumpLog(); + // fill proc with events from the given data and time period if (proc.containsKey("queries")) { List events = AccessTracker.readLog(AccessTracker.getDumpFile(), fromDate, toDate); diff --git a/source/net/yacy/search/query/AccessTracker.java b/source/net/yacy/search/query/AccessTracker.java index b1b1b86c2..07d379873 100644 --- a/source/net/yacy/search/query/AccessTracker.java +++ b/source/net/yacy/search/query/AccessTracker.java @@ -38,7 +38,6 @@ import java.util.Date; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.regex.Pattern; import net.yacy.cora.date.GenericFormatter; import net.yacy.cora.document.WordCache; @@ -235,13 +234,22 @@ public class AccessTracker { ByteArrayInputStream bais = new ByteArrayInputStream(buffer); BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "UTF-8")); String line; - Pattern sp = Pattern.compile(" "); while ((line = reader.readLine()) != null) { // parse the line - String[] ls = sp.split(line); + if (line.length() < GenericFormatter.PATTERN_SHORT_SECOND.length() + 3 || + line.charAt(GenericFormatter.PATTERN_SHORT_SECOND.length()) != ' ') continue; + String dateStr = line.substring(0, GenericFormatter.PATTERN_SHORT_SECOND.length()); + int countEnd = -1; + for (int i = GenericFormatter.PATTERN_SHORT_SECOND.length() + 2; i < line.length(); i++) { + if (line.charAt(i) == ' ') { countEnd = i; break; } + } + if (countEnd == -1) continue; + String countStr = line.substring(GenericFormatter.PATTERN_SHORT_SECOND.length() + 1, countEnd); + if (countStr.length() > 5) continue; + int hits = countStr.length() == 1 ? (countStr.charAt(0)) - 48 : Integer.parseInt(countStr); EventTracker.Event event; - if (ls.length > 1) try { - event = new EventTracker.Event(ls[0], 0, "query", line.substring(ls[0].length() + ls[1].length() + 2), Integer.valueOf(ls[1])); + try { + event = new EventTracker.Event(dateStr, 0, "query", line.substring(dateStr.length() + countStr.length() + 2), hits); events.add(event); } catch (NumberFormatException e) { continue;