Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the notifier database lazily #657

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -82,14 +82,7 @@ private Set<PullRequestState> deserializePrState(String current) {

// Storage might be missing commit information
if (!obj.contains("commit")) {
var prId = id.split(":")[1];
var currentPR = pr.repository().pullRequest(prId);
var hash = resultingCommitHashFor(currentPR);
if (hash == null) {
obj.putNull("commit");
} else {
obj.put("commit", hash.hex());
}
obj.put("commit", Hash.zero().hex());
}

var commit = obj.get("commit").isNull() ?
@@ -116,11 +109,16 @@ private String serializePrState(Collection<PullRequestState> added, Set<PullRequ
.stream()
.map(JSON::of)
.collect(Collectors.toList()));
var commit = pr.commitId().isPresent()?
JSON.of(pr.commitId().get().hex()) : JSON.of();
return JSON.object().put("pr", pr.prId())
.put("issues",issues)
.put("commit", commit);
var ret = JSON.object().put("pr", pr.prId())
.put("issues",issues);
if (pr.commitId().isPresent()) {
if (!pr.commitId().get().equals(Hash.zero())) {
ret.put("commit", JSON.of(pr.commitId().get().hex()));
}
} else {
ret.putNull("commit");
}
return ret;
})
.map(JSONObject::toString)
.collect(Collectors.toList());
@@ -193,6 +191,13 @@ public Collection<WorkItem> run(Path scratchPath) {
var storedState = stored.stream()
.filter(ss -> ss.prId().equals(state.prId()))
.findAny();
// The stored entry could be old and be missing commit information - if so, upgrade it
if (storedState.isPresent() && storedState.get().commitId().equals(Optional.of(Hash.zero()))) {
var hash = resultingCommitHashFor(pr);
storedState = Optional.of(new PullRequestState(pr, storedState.get().issueIds(), hash));
storage.put(storedState.get());
}

if (storedState.isPresent()) {
var storedIssues = storedState.get().issueIds();
storedIssues.stream()