From 807901c719934c1aa666ef3626923d4cb84cb9c3 Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Sun, 17 Feb 2019 22:51:11 +0200 Subject: [PATCH] additional fixes for #79: chunked http log use correct sqlite column name remove redundant code, tidy implementation --- src/laminar.cpp | 5 ++--- src/server.cpp | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/laminar.cpp b/src/laminar.cpp index a7d3c73..0d746f4 100644 --- a/src/laminar.cpp +++ b/src/laminar.cpp @@ -126,7 +126,7 @@ uint Laminar::latestRun(std::string job) { auto it = activeJobs.byJobName().equal_range(job); if(it.first == it.second) { uint result = 0; - db->stmt("SELECT MAX(buildNum) FROM builds WHERE name = ?") + db->stmt("SELECT MAX(number) FROM builds WHERE name = ?") .bind(job) .fetch([&](uint x){ result = x; @@ -145,8 +145,7 @@ bool Laminar::handleLogRequest(std::string name, uint num, std::string& output, complete = false; return true; } else { // it must be finished, fetch it from the database - const char* stmt = num == 0 ? "SELECT output, outputLen FROM builds WHERE name = ? ORDER BY number DESC LIMIT 1" : "SELECT output, outputLen FROM builds WHERE name = ? AND number = ?" ; - db->stmt(stmt) + db->stmt("SELECT output, outputLen FROM builds WHERE name = ? AND number = ?") .bind(name, num) .fetch([&](str maybeZipped, unsigned long sz) { str log(sz,'\0'); diff --git a/src/server.cpp b/src/server.cpp index 7e61747..ba6d297 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -356,10 +356,11 @@ private: name = path.slice(0, *sep).begin(); kj::StringPtr tail = path.slice(*sep+1); num = static_cast(atoi(tail.begin())); - if(num > 0 || tail == "latest") { - name.erase(*sep); + name.erase(*sep); + if(tail == "latest") + num = laminar.latestRun(name); + if(num > 0) return true; - } } } return false; @@ -407,8 +408,6 @@ private: } else if(parseLogEndpoint(url, name, num)) { kj::Own cc = kj::heap(laminar); cc->scope.job = name; - if(num == 0) - num = laminar.latestRun(name); cc->scope.num = num; bool complete; std::string output;