Skip to content

Commit

Permalink
refactor saving revision timestamp (#25)
Browse files Browse the repository at this point in the history
* refactor saving revision timestamp

* removed unnecessary ordering.
  • Loading branch information
alexsilaghi authored Oct 30, 2024
1 parent c4287e2 commit 85af92f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 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 @@ -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

0 comments on commit 85af92f

Please sign in to comment.