You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2015/11/12 20:44:06 UTC

[5/5] usergrid git commit: Call foreach on the set directly and only call createEntityIndex on a unique set of appIds.

Call foreach on the set directly and only call createEntityIndex on a unique set of appIds.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/b8956439
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/b8956439
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/b8956439

Branch: refs/heads/2.1-release
Commit: b89564398e1094203d224a1586103fe9298d12d9
Parents: f13e45b
Author: Michael Russo <mi...@gmail.com>
Authored: Thu Nov 12 11:39:17 2015 -0800
Committer: Michael Russo <mi...@gmail.com>
Committed: Thu Nov 12 11:39:17 2015 -0800

----------------------------------------------------------------------
 .../asyncevents/AmazonAsyncEventService.java    | 34 +++++++++++---------
 1 file changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/b8956439/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
index b5e77c1..e3b60a6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
@@ -570,26 +570,28 @@ public class AmazonAsyncEventService implements AsyncEventService {
      * @param indexOperationMessage
      */
     private void initializeEntityIndexes(final IndexOperationMessage indexOperationMessage) {
-        final Map<UUID,Boolean> apps = new HashMap<>(indexOperationMessage.getIndexRequests().size()+indexOperationMessage.getDeIndexRequests().size());
-        //loop through all adds
-        for(IndexOperation req : indexOperationMessage.getIndexRequests()) {
-            final UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId);
-            if(!apps.containsKey(appId)) {
-                ApplicationScope appScope = CpNamingUtils.getApplicationScope(appId);
-                entityIndexFactory.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(appScope));
-                apps.put(appId,true);
-            }
-        };
 
-        //loop through all deletes
-        for(DeIndexOperation req : indexOperationMessage.getDeIndexRequests()) {
-            final UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId);
-            if(!apps.containsKey(appId)) {
+        // create a set so we can have a unique list of appIds for which we call createEntityIndex
+        Set<UUID> appIds = new HashSet<>();
+
+        // loop through all indexRequests and add the appIds to the set
+        indexOperationMessage.getIndexRequests().forEach(req -> {
+            UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId);
+            appIds.add(appId);
+        });
+
+        // loop through all deindexRequests and add the appIds to the set
+        indexOperationMessage.getDeIndexRequests().forEach(req -> {
+            UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId);
+            appIds.add(appId);
+        });
+
+        // for each of the appIds in the unique set, call create entity index to ensure the aliases are created
+        appIds.forEach(appId -> {
                 ApplicationScope appScope = CpNamingUtils.getApplicationScope(appId);
                 entityIndexFactory.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(appScope));
-                apps.put(appId,true);
             }
-        };
+        );
     }