Commit 619f3d94 by xupeng

修正临时文件一直追加问题

parent c8a7957b
...@@ -117,9 +117,11 @@ public class QueryPlanHelper { ...@@ -117,9 +117,11 @@ public class QueryPlanHelper {
} }
long nowSecond = System.currentTimeMillis()/1000; long nowSecond = System.currentTimeMillis()/1000;
long sevenDays = 3600 * 24 * 7; long sevenDays = 3600 * 24 * 7;
boolean appendToFile = true;
if (nowSecond - minTimeStamp > sevenDays) { if (nowSecond - minTimeStamp > sevenDays) {
// 文件中最早的时间戳超过7天,全量更新;否则只更新新增的 // 文件中最早的时间戳超过7天,全量更新;否则只更新新增的
if (keywordMap.size() > 0) { if (keywordMap.size() > 0) {
appendToFile = false;
newWordLines = new ArrayList<>(); // map转存到newWordLines newWordLines = new ArrayList<>(); // map转存到newWordLines
for (Map.Entry<String, Integer> entry : keywordMap.entrySet()) { for (Map.Entry<String, Integer> entry : keywordMap.entrySet()) {
String line = entry.getKey() + "," + entry.getValue() + "," + nowSecond; String line = entry.getKey() + "," + entry.getValue() + "," + nowSecond;
...@@ -129,7 +131,7 @@ public class QueryPlanHelper { ...@@ -129,7 +131,7 @@ public class QueryPlanHelper {
} }
} }
if (newWordLines != null && newWordLines.size() > 0) { if (newWordLines != null && newWordLines.size() > 0) {
FileUtils.saveToFile(newWordLines, queryPlanFile, true); FileUtils.saveToFile(newWordLines, queryPlanFile, appendToFile);
newWordLines = new ArrayList<>(); newWordLines = new ArrayList<>();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment