This is an automated email from the ASF dual-hosted git repository.

dpavlov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git


The following commit(s) were added to refs/heads/master by this push:
     new d4a0f6c  Avoid saving history, timestamps moved to in-memory
d4a0f6c is described below

commit d4a0f6ce01976db39b1c09b8f9291498869f7895
Author: Dmitriy Pavlov <[email protected]>
AuthorDate: Fri Sep 21 13:24:34 2018 +0300

    Avoid saving history, timestamps moved to in-memory
---
 .../apache/ignite/ci/IgnitePersistentTeamcity.java | 39 ++++++++++++++++------
 .../org/apache/ignite/ci/IgniteTeamcityHelper.java | 11 +++---
 .../org/apache/ignite/ci/web/model/Version.java    |  2 +-
 3 files changed, 37 insertions(+), 15 deletions(-)

diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
index 8ea41ce..3983e81 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
@@ -130,6 +130,9 @@ public class IgnitePersistentTeamcity implements 
IAnalyticsEnabledTeamcity, ITea
     /** cached loads of running builds for branch. */
     private ConcurrentMap<String, CompletableFuture<List<BuildRef>>> 
runningBuildsFuts = new ConcurrentHashMap<>();
 
+    /**   */
+    private ConcurrentMap<SuiteInBranch, Long> lastQueuedHistory = new 
ConcurrentHashMap<>();
+
     //todo: not good code to keep it static
     private static long lastTriggerMs = System.currentTimeMillis();
 
@@ -274,15 +277,15 @@ public class IgnitePersistentTeamcity implements 
IAnalyticsEnabledTeamcity, ITea
         return loaded;
     }
 
-    protected <K> List<BuildRef> loadBuildHistory(IgniteCache<K, 
Expirable<List<BuildRef>>> cache,
-                                                  int seconds,
-                                                  Long cnt,
-                                                  K key,
-                                                  BiFunction<K, Integer, 
List<BuildRef>> realLoad) {
-        @Nullable Expirable<List<BuildRef>> persistedBuilds = 
readBuildHistEntry(cache, (K) key);
+    protected List<BuildRef> loadBuildHistory(IgniteCache<SuiteInBranch, 
Expirable<List<BuildRef>>> cache,
+                                              int seconds,
+                                              Long cnt,
+                                              SuiteInBranch key,
+                                              BiFunction<SuiteInBranch, 
Integer, List<BuildRef>> realLoad) {
+        @Nullable Expirable<List<BuildRef>> persistedBuilds = 
readBuildHistEntry(cache, key);
 
         if (persistedBuilds != null
-                && (persistedBuilds.isAgeLessThanSecs(seconds)
+                && (isHistoryAgeLessThanSecs(key, seconds, persistedBuilds)
                 && (cnt == null || 
persistedBuilds.hasCounterGreaterThan(cnt)))) {
             ObjectInterner.internFields(persistedBuilds);
 
@@ -294,7 +297,7 @@ public class IgnitePersistentTeamcity implements 
IAnalyticsEnabledTeamcity, ITea
         try {
             if (!noLocks) {
                 if (persistedBuilds != null
-                        && (persistedBuilds.isAgeLessThanSecs(seconds)
+                        && (isHistoryAgeLessThanSecs(key, seconds, 
persistedBuilds)
                         && (cnt == null || 
persistedBuilds.hasCounterGreaterThan(cnt)))) {
                     ObjectInterner.internFields(persistedBuilds);
 
@@ -334,11 +337,17 @@ public class IgnitePersistentTeamcity implements 
IAnalyticsEnabledTeamcity, ITea
             final List<BuildRef> persistedList = persistedBuilds != null ? 
persistedBuilds.getData() : null;
             final List<BuildRef> buildRefs = mergeHistoryMaps(persistedList, 
dataFromRest);
 
-            final Expirable<List<BuildRef>> newVal
-                    = new Expirable<>(System.currentTimeMillis(), 
buildRefs.size(), buildRefs);
+            final Expirable<List<BuildRef>> newVal = new Expirable<>(0L, 
buildRefs.size(), buildRefs);
+
+            if (persistedList != null && persistedList.equals(buildRefs)) {
+                lastQueuedHistory.put(key, System.currentTimeMillis());
 
+                return buildRefs;
+            }
             saveBuildHistoryEntry(cache, key, newVal);
 
+            lastQueuedHistory.put(key, System.currentTimeMillis());
+
             return buildRefs;
         }
         finally {
@@ -347,6 +356,16 @@ public class IgnitePersistentTeamcity implements 
IAnalyticsEnabledTeamcity, ITea
         }
     }
 
+    private boolean isHistoryAgeLessThanSecs(SuiteInBranch key, int seconds, 
Expirable<List<BuildRef>> persistedBuilds) {
+        Long loaded = lastQueuedHistory.get(key);
+        if (loaded == null)
+            return false;
+
+        long ageMs = System.currentTimeMillis() - loaded;
+
+        return ageMs < TimeUnit.SECONDS.toMillis(seconds);
+    }
+
     @AutoProfiling
     @SuppressWarnings("WeakerAccess")
     protected <K> void saveBuildHistoryEntry(IgniteCache<K, 
Expirable<List<BuildRef>>> cache, K key, Expirable<List<BuildRef>> newVal) {
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityHelper.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityHelper.java
index ffe66e2..c4bb00f 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityHelper.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityHelper.java
@@ -619,10 +619,13 @@ public class IgniteTeamcityHelper implements ITeamcity {
         return 
finished.stream().filter(BuildRef::isNotCancelled).collect(Collectors.toList());
     }
 
-    private List<BuildRef> getBuildsInState(
-        @Nullable final String projectId,
-        @Nullable final String branch,
-        @Nonnull final String state) {
+
+    @SuppressWarnings("WeakerAccess")
+    @AutoProfiling
+    protected List<BuildRef> getBuildsInState(
+            @Nullable final String projectId,
+            @Nullable final String branch,
+            @Nonnull final String state) {
 
         return getBuildsInState(projectId, branch, state, null, null);
     }
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
index 2e4879d..c1082a9 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
@@ -22,7 +22,7 @@ package org.apache.ignite.ci.web.model;
     public static final String DEFAULT_CONTACT = "[email protected]";
 
     /** TC Helper Version. */
-    public String version = "20180920";
+    public String version = "20180921";
 
     /** Ignite version. */
     public String ignVer;

Reply via email to