Commit 6f087c6a authored by alain's avatar alain 🐙

fix nextlink filter / redis cache key to include date start/end

parent 74d9e8a7
......@@ -108,10 +108,11 @@ def retrieveSensorData(params)
date_end = params[:end]
uri = "#{$base_url}/Things?$filter=name%20eq%20%27HLL_hl_device_#{id}%27&$expand=Datastreams($filter=contains(name,%27#{type}%27))"
cache_key = "#{uri}_#{date_start}_#{date_end}"
body = nil
if($redis.exists uri)
body = $redis.get uri
if($redis.exists cache_key)
body = $redis.get cache_key
puts "cache hit"
else
......@@ -136,7 +137,7 @@ def retrieveSensorData(params)
{ds_names[index] => all_values.flatten}
}
body = all_pages.to_json
$redis.set uri, body, {:ex => 3600}
$redis.set cache_key, body, {:ex => 3600}
end
body
end
......@@ -147,7 +148,7 @@ def getPageRecursive(pages,uri,filter)
response = RestClient.get uri
page = JSON.parse(response)
nextLink = page["@iot.nextLink"]
nextLink = nextLink + "&$select=phenomenonTime,result" if(filter)
nextLink = "#{nextLink}&$select=phenomenonTime,result" if(filter and nextLink != nil and not nextLink.empty?)
pages << page
getPageRecursive(pages,nextLink,filter) if (nextLink != nil and not nextLink.empty?)
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment