Skip to content

Commit

Permalink
refactor saving revision timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilaghi committed Oct 29, 2024
1 parent c4287e2 commit 7879952
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
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 @@ -69,7 +69,7 @@ public Optional<EntityLinearizationHistory> getExistingHistoryOrderedByRevision(
.map(history -> {
Set<LinearizationRevision> sortedRevisions = history.getLinearizationRevisions()
.stream()
.sorted(Comparator.comparingLong(LinearizationRevision::timestamp))
.sorted(Comparator.comparingLong(LinearizationRevision::timestamp).reversed())
.collect(Collectors.toCollection(TreeSet::new));
// Return a new EntityLinearizationHistory object with the sorted revisions
return new EntityLinearizationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions);
Expand Down

0 comments on commit 7879952

Please sign in to comment.