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

refactor saving revision timestamp #25

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@ public record LinearizationRevision(@Indexed(name = "timestamp", direction = Ind
public static final String USER_ID = "userId";
public static final String LINEARIZATION_EVENTS = "linearizationEvents";

private static long lastTimestamp = 0;
private static int counter = 0;

public static LinearizationRevision create(UserId userId, Set<LinearizationEvent> linearizationEvents) {
long currentTimestamp = Instant.now().toEpochMilli();
if (currentTimestamp == lastTimestamp) {
counter++;
} else {
lastTimestamp = currentTimestamp;
counter = 0;
}
return new LinearizationRevision(currentTimestamp + counter, userId, linearizationEvents);
return new LinearizationRevision(new Date().getTime(), userId, linearizationEvents);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ public void saveMultipleEntityLinearizationHistories(Set<EntityLinearizationHist
public Optional<EntityLinearizationHistory> getExistingHistoryOrderedByRevision(IRI entityIri, ProjectId projectId) {
return linearizationHistoryRepository.findHistoryByEntityIriAndProjectId(entityIri.toString(), projectId)
.map(history -> {
Set<LinearizationRevision> sortedRevisions = history.getLinearizationRevisions()
.stream()
.sorted(Comparator.comparingLong(LinearizationRevision::timestamp))
.collect(Collectors.toCollection(TreeSet::new));
Set<LinearizationRevision> sortedRevisions = new TreeSet<>(history.getLinearizationRevisions());
// Return a new EntityLinearizationHistory object with the sorted revisions
return new EntityLinearizationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions);
});
Expand Down
Loading