aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly.no>2016-03-16 19:31:48 +0000
committerKristian Lyngstol <kly@kly.no>2016-03-16 19:31:48 +0000
commit314bc052854aabb44dd9272ddd82176be5c469d5 (patch)
treef24943727a66aa32cb231830cd5f1f214d12ceb5 /include
parent77525f31852c93f7e336b0172a9f87674941fd09 (diff)
NMS: Implement improved ping map
e69-2 is looking good. Now with a separate age-entity. Not really used for anything fancy right now, but could be.
Diffstat (limited to 'include')
-rwxr-xr-xinclude/nms/web.pm13
1 files changed, 9 insertions, 4 deletions
diff --git a/include/nms/web.pm b/include/nms/web.pm
index 2a336c6..7372916 100755
--- a/include/nms/web.pm
+++ b/include/nms/web.pm
@@ -52,15 +52,20 @@ sub db_safe_quote {
# returns a valid $when statement
# Also sets cache-control headers if time is overridden
+# This can be called explicitly to override the window of time we evaluate.
+# Normally up to 15 minutes old data will be returned, but for some API
+# endpoints it is better to return no data than old data (e.g.: ping).
sub setwhen {
- my $when;
$now = "now()";
+ my $window = '15m';
+ if (@_ == 1) {
+ $window = $_[0];
+ }
if (defined($get_params{'now'})) {
$now = db_safe_quote('now') . "::timestamp ";
$cc{'max-age'} = "3600";
}
- $when = " time > " . $now . " - '15m'::interval and time < " . $now . " ";
- return $when;
+ $when = " time > " . $now . " - '".$window."'::interval and time < " . $now . " ";
}
sub finalize_output {
@@ -93,6 +98,6 @@ BEGIN {
$dbh = nms::db_connect();
populate_params();
- $when = setwhen();
+ setwhen();
}
1;