Commit 805fd38d authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Sort matches first by timestamp, then by fingerprint.

A while ago, in 92cbc074, 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.
parent 93a0d52e
......@@ -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
......
......@@ -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<>();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment