Store information about starring changes in notedb

To keep track of a change that is starred by a user we create a
refs/starred-changes/YY/XXXX/ZZZZ ref in the All-Users notedb
repository, where YY/XXXX is the sharded account ID and ZZZZ is the
numeric change ID. The refs/starred-changes/* refs point to empty tree
objects since the existence of a ref is enough to know that a change
was starred by a user. The ref format is similar to the
refs/draft-comments/* refs that store draft comments in the All-Users
notedb repository, but it uses '/' instead of '-' to separate the
sharded account ID from the change ID. This is because we need to find
all refs that start with the prefix refs/starred-changes/YY/XXXX/ and
RefDirectory in jgit has explicit optimizations for the case when the
prefix ends with '/' and we want to take advantage of this.

Change-Id: I033b35a05749929c9c0ea778075c4a1085c5bf2a
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-11-11 17:40:30 -08:00
parent 821754e71a
commit 17c33ce0ad
14 changed files with 434 additions and 83 deletions

View File

@@ -189,6 +189,7 @@ public class ChangeUtil {
private final BatchUpdate.Factory updateFactory;
private final ChangeMessagesUtil changeMessagesUtil;
private final ChangeUpdate.Factory changeUpdateFactory;
private final StarredChangesUtil starredChangesUtil;
@Inject
ChangeUtil(Provider<IdentifiedUser> user,
@@ -202,7 +203,8 @@ public class ChangeUtil {
ChangeIndexer indexer,
BatchUpdate.Factory updateFactory,
ChangeMessagesUtil changeMessagesUtil,
ChangeUpdate.Factory changeUpdateFactory) {
ChangeUpdate.Factory changeUpdateFactory,
StarredChangesUtil starredChangesUtil) {
this.user = user;
this.db = db;
this.queryProvider = queryProvider;
@@ -215,6 +217,7 @@ public class ChangeUtil {
this.updateFactory = updateFactory;
this.changeMessagesUtil = changeMessagesUtil;
this.changeUpdateFactory = changeUpdateFactory;
this.starredChangesUtil = starredChangesUtil;
}
public Change.Id revert(ChangeControl ctl, PatchSet.Id patchSetId,
@@ -366,7 +369,7 @@ public class ChangeUtil {
db.patchSetApprovals().delete(db.patchSetApprovals().byChange(changeId));
db.patchSets().delete(patchSets);
db.changeMessages().delete(db.changeMessages().byChange(changeId));
db.starredChanges().delete(db.starredChanges().byChange(changeId));
starredChangesUtil.unstarAll(changeId);
db.changes().delete(Collections.singleton(change));
// Delete all refs at once.