Assume labels are correct in ListChanges
To reduce end-user latency when displaying changes in a search result or user dashboard, assume the labels are accurate in the database at display time and don't recompute the access privileges of a reviewer. Change-Id: I1316adf627e88fdcde1cd845444d56da9abaeb57
This commit is contained in:
@@ -292,11 +292,11 @@ public class ChangeControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet) {
|
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet) {
|
||||||
return canSubmit(db, patchSet, null);
|
return canSubmit(db, patchSet, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet,
|
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet,
|
||||||
@Nullable ChangeData cd) {
|
@Nullable ChangeData cd, boolean fastEvalLabels) {
|
||||||
if (change.getStatus().isClosed()) {
|
if (change.getStatus().isClosed()) {
|
||||||
SubmitRecord rec = new SubmitRecord();
|
SubmitRecord rec = new SubmitRecord();
|
||||||
rec.status = SubmitRecord.Status.CLOSED;
|
rec.status = SubmitRecord.Status.CLOSED;
|
||||||
@@ -353,6 +353,10 @@ public class ChangeControl {
|
|||||||
+ getProject().getName());
|
+ getProject().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fastEvalLabels) {
|
||||||
|
env.once("gerrit", "assume_range_from_label");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Term[] template : env.all(
|
for (Term[] template : env.all(
|
||||||
"gerrit", "can_submit",
|
"gerrit", "can_submit",
|
||||||
@@ -391,6 +395,10 @@ public class ChangeControl {
|
|||||||
parentEnv.once("gerrit", "locate_submit_filter", new VariableTerm());
|
parentEnv.once("gerrit", "locate_submit_filter", new VariableTerm());
|
||||||
if (filterRule != null) {
|
if (filterRule != null) {
|
||||||
try {
|
try {
|
||||||
|
if (fastEvalLabels) {
|
||||||
|
env.once("gerrit", "assume_range_from_label");
|
||||||
|
}
|
||||||
|
|
||||||
Term resultsTerm = toListTerm(results);
|
Term resultsTerm = toListTerm(results);
|
||||||
results.clear();
|
results.clear();
|
||||||
Term[] template = parentEnv.once(
|
Term[] template = parentEnv.once(
|
||||||
|
@@ -226,7 +226,7 @@ public class ListChanges {
|
|||||||
|
|
||||||
PatchSet ps = cd.currentPatchSet(db);
|
PatchSet ps = cd.currentPatchSet(db);
|
||||||
Map<String, LabelInfo> labels = Maps.newLinkedHashMap();
|
Map<String, LabelInfo> labels = Maps.newLinkedHashMap();
|
||||||
for (SubmitRecord rec : ctl.canSubmit(db.get(), ps, cd)) {
|
for (SubmitRecord rec : ctl.canSubmit(db.get(), ps, cd, true)) {
|
||||||
if (rec.labels == null) {
|
if (rec.labels == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -25,8 +25,7 @@
|
|||||||
%% predicate that needs to obtain it.
|
%% predicate that needs to obtain it.
|
||||||
%%
|
%%
|
||||||
init :-
|
init :-
|
||||||
define_hash(commit_labels),
|
define_hash(commit_labels).
|
||||||
define_hash(current_user).
|
|
||||||
|
|
||||||
define_hash(A) :- hash_exists(A), !, hash_clear(A).
|
define_hash(A) :- hash_exists(A), !, hash_clear(A).
|
||||||
define_hash(A) :- atom(A), !, new_hash(_, [alias(A)]).
|
define_hash(A) :- atom(A), !, new_hash(_, [alias(A)]).
|
||||||
@@ -97,6 +96,10 @@ index_commit_labels([_ | Rs]) :-
|
|||||||
%%
|
%%
|
||||||
%% Lookup the range allowed to be used.
|
%% Lookup the range allowed to be used.
|
||||||
%%
|
%%
|
||||||
|
user_label_range(Label, Who, Min, Max) :-
|
||||||
|
hash_get(commit_labels, '$fast_range', true), !,
|
||||||
|
atom(Label),
|
||||||
|
assume_range_from_label(Label, Who, Min, Max).
|
||||||
user_label_range(Label, Who, Min, Max) :-
|
user_label_range(Label, Who, Min, Max) :-
|
||||||
Who = user(_), !,
|
Who = user(_), !,
|
||||||
atom(Label),
|
atom(Label),
|
||||||
@@ -106,6 +109,14 @@ user_label_range(Label, test_user(Name), Min, Max) :-
|
|||||||
clause(user:test_grant(Label, test_user(Name), range(Min, Max)), _)
|
clause(user:test_grant(Label, test_user(Name), range(Min, Max)), _)
|
||||||
.
|
.
|
||||||
|
|
||||||
|
assume_range_from_label :-
|
||||||
|
hash_put(commit_labels, '$fast_range', true).
|
||||||
|
|
||||||
|
assume_range_from_label(Label, Who, Min, Max) :-
|
||||||
|
commit_label(label(Label, Value), Who), !,
|
||||||
|
Min = Value, Max = Value.
|
||||||
|
assume_range_from_label(_, _, 0, 0).
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%%
|
%%
|
||||||
|
Reference in New Issue
Block a user