diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-12-27 11:36:51 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-12-27 11:36:51 +0100 |
commit | 37c3981796f246d0c7a5b5d11eace41c989c7883 (patch) | |
tree | 8668df92a7e9e615d55b4c9c637597d9040022db | |
parent | 4bb5f83fe7275addd62aa483c43a860ce173a55e (diff) |
Sort by log entry time and then ID
-rw-r--r-- | sql/sql.go | 2 | ||||
-rw-r--r-- | sql/sql_test.go | 4 |
2 files changed, 5 insertions, 1 deletions
@@ -103,7 +103,7 @@ INNER JOIN rr_question ON rr_question.id = rr_question_id INNER JOIN rr_type ON rr_type.id = rr_type_id INNER JOIN log_rr_answer ON log_rr_answer.log_id = log.id INNER JOIN rr_answer ON rr_answer.id = log_rr_answer.rr_answer_id -WHERE log.id IN (SELECT id FROM log ORDER BY time DESC LIMIT $1) +WHERE log.id IN (SELECT id FROM log ORDER BY time DESC, id DESC LIMIT $1) ORDER BY time DESC, rr_answer.id DESC ` var entries []LogEntry diff --git a/sql/sql_test.go b/sql/sql_test.go index 6328dc6..3655a66 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -33,6 +33,8 @@ var tests = []struct { []rowCount{{"rr_question", 2}, {"rr_answer", 3}, {"log", 5}, {"rr_type", 2}, {"remote_addr", 3}}}, {"bar.example.com", 28, []string{"2001:db8::2", "2001:db8::3"}, time.Date(2019, 6, 15, 23, 35, 0, 0, time.UTC), net.IPv4(192, 0, 2, 102), []rowCount{{"rr_question", 2}, {"rr_answer", 5}, {"log", 6}, {"rr_type", 2}, {"remote_addr", 3}}}, + {"baz.example.com", 28, []string{"2001:db8::4"}, time.Date(2019, 6, 15, 23, 35, 0, 0, time.UTC), net.IPv4(192, 0, 2, 102), + []rowCount{{"rr_question", 3}, {"rr_answer", 6}, {"log", 7}, {"rr_type", 2}, {"remote_addr", 3}}}, } func testClient() *Client { @@ -74,6 +76,7 @@ func TestReadLog(t *testing.T) { } } allEntries := [][]LogEntry{ + {{ID: 7, Question: "baz.example.com", Qtype: 28, Answer: "2001:db8::4", Time: 1560641700, RemoteAddr: net.IPv4(192, 0, 2, 102)}}, { {ID: 6, Question: "bar.example.com", Qtype: 28, Answer: "2001:db8::3", Time: 1560641700, RemoteAddr: net.IPv4(192, 0, 2, 102)}, {ID: 6, Question: "bar.example.com", Qtype: 28, Answer: "2001:db8::2", Time: 1560641700, RemoteAddr: net.IPv4(192, 0, 2, 102)}, @@ -112,6 +115,7 @@ func TestDeleteLogBefore(t *testing.T) { } want := []LogEntry{ + {ID: 7, Question: "baz.example.com", Qtype: 28, Answer: "2001:db8::4", Time: 1560641700, RemoteAddr: net.IPv4(192, 0, 2, 102)}, {ID: 6, Question: "bar.example.com", Qtype: 28, Answer: "2001:db8::3", Time: 1560641700, RemoteAddr: net.IPv4(192, 0, 2, 102)}, {ID: 6, Question: "bar.example.com", Qtype: 28, Answer: "2001:db8::2", Time: 1560641700, RemoteAddr: net.IPv4(192, 0, 2, 102)}, {ID: 5, Question: "bar.example.com", Qtype: 28, Answer: "2001:db8::1", Time: 1560639880, RemoteAddr: net.IPv4(192, 0, 2, 102)}, |