From 7879952043b9b16ca1c045af33a9c9b3eed99415 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Tue, 29 Oct 2024 12:33:49 +0200 Subject: [PATCH 1/2] refactor saving revision timestamp --- .../model/LinearizationRevision.java | 12 +----------- .../services/LinearizationHistoryServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java index a830192..b45d4a4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java @@ -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 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 diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java index 7d55f7b..d46a57c 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java @@ -69,7 +69,7 @@ public Optional getExistingHistoryOrderedByRevision( .map(history -> { Set 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); From 038b31c09aa44f2ba2b546eb2669424364940ca8 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Wed, 30 Oct 2024 12:27:35 +0200 Subject: [PATCH 2/2] removed unnecessary ordering. --- .../services/LinearizationHistoryServiceImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java index d46a57c..a45bc66 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java @@ -67,10 +67,7 @@ public void saveMultipleEntityLinearizationHistories(Set getExistingHistoryOrderedByRevision(IRI entityIri, ProjectId projectId) { return linearizationHistoryRepository.findHistoryByEntityIriAndProjectId(entityIri.toString(), projectId) .map(history -> { - Set sortedRevisions = history.getLinearizationRevisions() - .stream() - .sorted(Comparator.comparingLong(LinearizationRevision::timestamp).reversed()) - .collect(Collectors.toCollection(TreeSet::new)); + Set sortedRevisions = new TreeSet<>(history.getLinearizationRevisions()); // Return a new EntityLinearizationHistory object with the sorted revisions return new EntityLinearizationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions); });