Index: chrome/common/extensions/docs/server2/commit_tracker.py |
diff --git a/chrome/common/extensions/docs/server2/commit_tracker.py b/chrome/common/extensions/docs/server2/commit_tracker.py |
index 53bb90c9cd6306cb043dfc417797af951ae42f28..2da5d5db0399592f73552bbcd297fc56c9ae67b4 100644 |
--- a/chrome/common/extensions/docs/server2/commit_tracker.py |
+++ b/chrome/common/extensions/docs/server2/commit_tracker.py |
@@ -2,20 +2,52 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import collections |
+import datetime |
+ |
from object_store_creator import ObjectStoreCreator |
from future import Future |
+# The maximum number of commit IDs to retain in a named commit's history deque. |
+_MAX_COMMIT_HISTORY_LENGTH = 50 |
+ |
+ |
+class CachedCommit(object): |
+ '''Object type which is stored for each entry in a named commit's history.''' |
+ def __init__(self, commit_id, datetime): |
+ self.commit_id = commit_id |
+ self.datetime = datetime |
not at google - send to devlin
2014/11/19 19:32:41
Maybe mention what datetime is used for? Because I
Ken Rockot(use gerrit already)
2015/02/02 23:57:44
Done. FOR DISPLAY PURPOSES ONLY
|
+ |
+ |
class CommitTracker(object): |
'''Utility class for managing and querying the storage of various named commit |
IDs.''' |
def __init__(self, object_store_creator): |
- # The object store should never be created empty since the sole purpose of |
+ # The object stores should never be created empty since the sole purpose of |
# this tracker is to persist named commit data across requests. |
self._store = object_store_creator.Create(CommitTracker, start_empty=False) |
+ self._history_store = object_store_creator.Create(CommitTracker, |
+ category='history', start_empty=False) |
def Get(self, key): |
return self._store.Get(key) |
def Set(self, key, commit): |
- return self._store.Set(key, commit) |
+ return (self._store.Set(key, commit) |
+ .Then(lambda _: self._UpdateHistory(key, commit))) |
+ |
+ def GetHistory(self, key): |
+ '''Fetches the commit ID history for a named commit. If the commit has no |
+ history, this will return an empty collection.''' |
+ return (self._history_store.Get(key) |
+ .Then(lambda history: () if history is None else history)) |
+ |
+ def _UpdateHistory(self, key, commit): |
+ '''Appends a commit ID to a named commit's tracked history.''' |
+ def create_or_amend_history(history): |
+ if history is None: |
+ history = collections.deque([], maxlen=50) |
not at google - send to devlin
2014/11/19 19:32:41
You're sure that .deque() pickles and unpickles pr
Ken Rockot(use gerrit already)
2015/02/02 23:57:44
Yar, deques support pickling
|
+ history.append(CachedCommit(commit, datetime.datetime.now())) |
+ return self._history_store.Set(key, history) |
+ return self._history_store.Get(key).Then(create_or_amend_history) |