Support limiting the range when listing recordings

Now it's possible to quickly determine what calendar days have data and then
query recordings for just the day(s) of interest with their returned
{start,end}_time_usec.
This commit is contained in:
Scott Lamb 2016-05-03 05:17:06 -07:00
parent d07ecc877b
commit 7bdaf161cf
2 changed files with 38 additions and 10 deletions

View File

@ -113,14 +113,18 @@ Example response:
A GET returns information about recordings, in descending order.
Valid request parameters:
* `start_time_90k` and and `end_time_90k` limit the data returned to only
recordings which overlap with the given half-open interval. Either or both
may be absent; they default to the beginning and end of time, respectively.
* TODO(slamb): `continue` to support paging. (If data is too large, the
server should return a `continue` key which is expected to be returned on
following requests.)
TODO(slamb): once we support annotations, should they be included in the same
URI or as a separate `/annotations`?
TODO(slamb): this should support paging. The client can limit the range via
the URI parameters `start\_time\_90k` and `end\_time\_90k`. If the range is
too large, the server will return some fraction of the data along with a
continuation key to pass in for the next request.
TODO(slamb): There might be some irregularity in the order if there are
overlapping recordings (such as if the server's clock jumped while running)
but I haven't thought about the details. In general, I'm not really sure how
@ -172,7 +176,7 @@ Example response:
},
...
],
"continuation_key": "<opaque blob>",
"continue": "<opaque blob>",
}
```

View File

@ -46,6 +46,20 @@ namespace {
static const char kJsonMimeType[] = "application/json";
bool ParseOptionalStartAndEnd(const QueryParameters &params,
int64_t *start_time_90k, int64_t *end_time_90k) {
*start_time_90k = std::numeric_limits<int64_t>::min();
*end_time_90k = std::numeric_limits<int64_t>::max();
if (!params.ok() ||
(params.Get("start_time_90k") != nullptr &&
!Atoi64(params.Get("start_time_90k"), 10, start_time_90k)) ||
(params.Get("end_time_90k") != nullptr &&
!Atoi64(params.Get("end_time_90k"), 10, end_time_90k))) {
return false;
}
return true;
}
void ReplyWithJson(evhttp_request *req, const Json::Value &value) {
EvBuffer buf;
buf.Add(Json::FastWriter().write(value));
@ -186,6 +200,13 @@ void WebInterface::HandleHtmlCameraDetail(evhttp_request *req,
return evhttp_send_error(req, HTTP_NOTFOUND, "no such camera");
}
int64_t start_time_90k;
int64_t end_time_90k;
QueryParameters params(evhttp_request_get_uri(req));
if (!ParseOptionalStartAndEnd(params, &start_time_90k, &end_time_90k)) {
return evhttp_send_error(req, HTTP_BADREQUEST, "bad query parameters");
}
EvBuffer buf;
buf.AddPrintf(
"<!DOCTYPE html>\n"
@ -253,8 +274,6 @@ void WebInterface::HandleHtmlCameraDetail(evhttp_request *req,
}
return IterationControl::kContinue;
};
int64_t start_time_90k = 0;
int64_t end_time_90k = std::numeric_limits<int64_t>::max();
std::string error_message;
if (!env_->mdb->ListCameraRecordings(camera_uuid, start_time_90k,
end_time_90k, handle_sql_row,
@ -318,6 +337,13 @@ void WebInterface::HandleJsonCameraDetail(evhttp_request *req,
void WebInterface::HandleJsonCameraRecordings(evhttp_request *req,
Uuid camera_uuid) {
int64_t start_time_90k;
int64_t end_time_90k;
QueryParameters params(evhttp_request_get_uri(req));
if (!ParseOptionalStartAndEnd(params, &start_time_90k, &end_time_90k)) {
return evhttp_send_error(req, HTTP_BADREQUEST, "bad query parameters");
}
GetCameraRow camera_row;
if (!env_->mdb->GetCamera(camera_uuid, &camera_row)) {
return evhttp_send_error(req, HTTP_NOTFOUND, "no such camera");
@ -339,8 +365,6 @@ void WebInterface::HandleJsonCameraRecordings(evhttp_request *req,
recordings.append(recording);
return IterationControl::kContinue;
};
int64_t start_time_90k = 0;
int64_t end_time_90k = std::numeric_limits<int64_t>::max();
std::string error_message;
if (!env_->mdb->ListCameraRecordings(camera_uuid, start_time_90k,
end_time_90k, handle_row,