jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1414660 - /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
Date Wed, 28 Nov 2012 13:05:37 GMT
Author: meteatamel
Date: Wed Nov 28 13:05:36 2012
New Revision: 1414660

URL: http://svn.apache.org/viewvc?rev=1414660&view=rev
Log:
OAK-487 - FetchHeadRevisionIdAction is inefficient

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java?rev=1414660&r1=1414659&r2=1414660&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/action/FetchHeadRevisionIdAction.java
Wed Nov 28 13:05:36 2012
@@ -18,9 +18,13 @@ package org.apache.jackrabbit.mongomk.im
 
 import org.apache.jackrabbit.mongomk.impl.MongoNodeStore;
 import org.apache.jackrabbit.mongomk.impl.model.MongoCommit;
+import org.apache.jackrabbit.mongomk.impl.model.MongoNode;
 import org.apache.jackrabbit.mongomk.impl.model.MongoSync;
 
+import com.mongodb.BasicDBObject;
 import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
 
 /**
  * An action for fetching the head revision.
@@ -57,13 +61,14 @@ public class FetchHeadRevisionIdAction e
         }
 
         // Otherwise, find the first revision id that's not part of a branch.
-        long revisionId = headRevisionId;
-        while (true) {
-            MongoCommit commitMongo = new FetchCommitAction(nodeStore, revisionId).execute();
-            if (commitMongo.getBranchId() == null) {
-                return revisionId;
-            }
-            revisionId = commitMongo.getBaseRevisionId();
-        }
+        DBCollection collection = nodeStore.getCommitCollection();
+        DBObject query = QueryBuilder.start(MongoCommit.KEY_FAILED).notEquals(Boolean.TRUE)
+                .and(MongoCommit.KEY_REVISION_ID).lessThanEquals(headRevisionId)
+                .and(new BasicDBObject(MongoNode.KEY_BRANCH_ID, new BasicDBObject("$exists",
false)))
+                .get();
+        DBObject fields = new BasicDBObject(MongoCommit.KEY_REVISION_ID, 1);
+        DBObject orderBy = new BasicDBObject(MongoCommit.KEY_REVISION_ID, -1);
+        MongoCommit commit = (MongoCommit)collection.findOne(query, fields, orderBy);
+        return commit.getRevisionId();
     }
 }



Mime
View raw message