fix: stats flush ensures schema, query flushes pending, add sqlite round-trip test
This commit is contained in:
+36
-9
@@ -4,6 +4,8 @@
|
||||
// selects by method (plan 05, E7). Unimplemented methods throw 405 with the
|
||||
// view's Allow list; override allowed_methods() to list implemented ones.
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -17,6 +19,12 @@ namespace molo::app::views {
|
||||
|
||||
class View {
|
||||
public:
|
||||
// Zero-cost stats hook (reverse.md §9): set by realtime/expose at startup;
|
||||
// null by default so Views pay nothing. Args: method, bytes_in,
|
||||
// bytes_out, latency_us.
|
||||
using ObserveFn = void (*)(const std::string&, std::uint64_t, std::uint64_t,
|
||||
std::uint64_t);
|
||||
static void SetObserver(ObserveFn fn) { observer_ = fn; }
|
||||
explicit View(http_msg::Request& request) : request_(request) {}
|
||||
virtual ~View() = default;
|
||||
|
||||
@@ -33,16 +41,34 @@ class View {
|
||||
}
|
||||
|
||||
async::Task<http_msg::Response> dispatch() {
|
||||
switch (request_.method()) {
|
||||
case http_msg::Method::GET: co_return co_await get();
|
||||
case http_msg::Method::POST: co_return co_await post();
|
||||
case http_msg::Method::PUT: co_return co_await put();
|
||||
case http_msg::Method::PATCH: co_return co_await patch();
|
||||
case http_msg::Method::DELETE: co_return co_await del();
|
||||
case http_msg::Method::HEAD: co_return co_await head();
|
||||
case http_msg::Method::OPTIONS: co_return co_await options();
|
||||
if (observer_ == nullptr) {
|
||||
switch (request_.method()) {
|
||||
case http_msg::Method::GET: co_return co_await get();
|
||||
case http_msg::Method::POST: co_return co_await post();
|
||||
case http_msg::Method::PUT: co_return co_await put();
|
||||
case http_msg::Method::PATCH: co_return co_await patch();
|
||||
case http_msg::Method::DELETE: co_return co_await del();
|
||||
case http_msg::Method::HEAD: co_return co_await head();
|
||||
case http_msg::Method::OPTIONS: co_return co_await options();
|
||||
}
|
||||
co_return co_await method_not_allowed();
|
||||
}
|
||||
co_return co_await method_not_allowed();
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
http_msg::Response resp(500);
|
||||
switch (request_.method()) {
|
||||
case http_msg::Method::GET: resp = co_await get(); break;
|
||||
case http_msg::Method::POST: resp = co_await post(); break;
|
||||
case http_msg::Method::PUT: resp = co_await put(); break;
|
||||
case http_msg::Method::PATCH: resp = co_await patch(); break;
|
||||
case http_msg::Method::DELETE: resp = co_await del(); break;
|
||||
case http_msg::Method::HEAD: resp = co_await head(); break;
|
||||
case http_msg::Method::OPTIONS: resp = co_await options(); break;
|
||||
}
|
||||
auto us = (unsigned long long)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - t0).count();
|
||||
observer_(to_string(request_.method()), request_.body().size(),
|
||||
resp.body().size(), us);
|
||||
co_return resp;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -55,6 +81,7 @@ class View {
|
||||
}
|
||||
|
||||
http_msg::Request& request_;
|
||||
static inline ObserveFn observer_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace molo::app::views
|
||||
|
||||
Reference in New Issue
Block a user