commit 805fd38d22e94205ac3d1dd204ba5e2742ba56d7 Author: Karsten Loesing karsten.loesing@gmx.net Date: Fri Nov 17 10:59:08 2017 +0100
Sort matches first by timestamp, then by fingerprint.
A while ago, in 92cbc07, we took out ORDER BY statements, because we didn't need them anymore in order to produce correct output. However, this also made the technical details part less readable with entries appearing in random order. Let's fix this by sorting results first by timestamp and then by fingerprint.
Fixes #24327. --- CHANGELOG.md | 2 ++ .../java/org/torproject/metrics/exonerator/QueryServlet.java | 11 +++++++++++ 2 files changed, 13 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f4cb50..aaacf94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Rename root package org.torproject.exonerator to org.torproject.metrics.exonerator to make it part of the Tor Metrics name space. + - Sort results under technical details by timestamp and, if + necessary, by fingerprint.
# Changes in version 2.0.0 - 2017-11-14 diff --git a/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java b/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java index 2e44ed7..7406be5 100644 --- a/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java +++ b/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java @@ -18,6 +18,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.List; import java.util.SortedSet; import java.util.TimeZone; @@ -338,6 +339,16 @@ public class QueryServlet extends HttpServlet { } } if (!matches.isEmpty()) { + Collections.sort(matches, + (m1, m2) -> { + if (m1 == m2) { + return 0; + } else if (!m1.timestamp.equals(m2.timestamp)) { + return m1.timestamp.compareTo(m2.timestamp); + } else { + return m1.fingerprint.compareTo(m2.fingerprint); + } + }); response.matches = matches.toArray(new QueryResponse.Match[0]); } else { List<String> nearbyAddresses = new ArrayList<>();
tor-commits@lists.torproject.org