[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/master] Put last consensus valid-after time on relay-search page.



commit 30b1dd7344765ccda5c4043ad01d5420d707866a
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Sun Jun 16 19:16:04 2013 +0200

    Put last consensus valid-after time on relay-search page.
    
    Fixes #9073.
---
 .../status/relaysearch/RelaySearchServlet.java     |   27 ++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/org/torproject/ernie/status/relaysearch/RelaySearchServlet.java b/src/org/torproject/ernie/status/relaysearch/RelaySearchServlet.java
index 4e83bb5..cd5c4c1 100644
--- a/src/org/torproject/ernie/status/relaysearch/RelaySearchServlet.java
+++ b/src/org/torproject/ernie/status/relaysearch/RelaySearchServlet.java
@@ -276,6 +276,28 @@ public class RelaySearchServlet extends HttpServlet {
       return;
     }
 
+    /* Look up last consensus in the database. */
+    long maxValidAfterMillis = -1L;
+    try {
+      long requestedConnection = System.currentTimeMillis();
+      Connection conn = this.ds.getConnection();
+      String query = "SELECT MAX(validafter) AS last FROM consensus";
+      Statement statement = conn.createStatement();
+      ResultSet rs = statement.executeQuery(query);
+      if (rs.next()) {
+        maxValidAfterMillis = rs.getTimestamp(1).getTime();
+      }
+      rs.close();
+      statement.close();
+      conn.close();
+      this.logger.info("Returned a database connection to the pool "
+          + "after " + (System.currentTimeMillis()
+          - requestedConnection) + " millis.");
+    } catch (SQLException e) {
+      this.logger.log(Level.WARNING, "Could not look up last consensus "
+          + "valid-after time in the database.", e);
+    }
+
     /* Prepare a string that says what we're searching for. */
     List<String> recognizedSearchTerms = new ArrayList<String>();
     if (searchNickname.length() > 0) {
@@ -297,6 +319,11 @@ public class RelaySearchServlet extends HttpServlet {
       recognizedIntervals.add("on <b>" + searchTerm + "</b>");
     }
     StringBuilder searchNoticeBuilder = new StringBuilder();
+    if (maxValidAfterMillis > 0L) {
+      searchNoticeBuilder.append("Most recent consensus in database is "
+          + "from " + dateTimeFormat.format(maxValidAfterMillis)
+          + ".</p><p>");
+    }
     searchNoticeBuilder.append("Searching for relays with ");
     if (recognizedSearchTerms.size() == 1) {
       searchNoticeBuilder.append(recognizedSearchTerms.get(0));

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits