Cache data in fastapi side
This commit is contained in:
@@ -1406,12 +1406,6 @@ def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", c
|
||||
:return:
|
||||
"""
|
||||
|
||||
global influxdb_cache
|
||||
|
||||
cache_key = f"{query_date}"
|
||||
if influxdb_cache.get(cache_key) is not None:
|
||||
return influxdb_cache.get(cache_key)
|
||||
|
||||
if client.ping(): print("{} -- Successfully connected to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
||||
else: print("{} -- Failed to connect to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
||||
|
||||
@@ -1457,8 +1451,6 @@ def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", c
|
||||
except Exception as e:
|
||||
print(f"Error querying InfluxDB for date {query_date}: {e}")
|
||||
|
||||
influxdb_cache[cache_key] = SCADA_results
|
||||
|
||||
return SCADA_results
|
||||
|
||||
|
||||
@@ -1842,8 +1834,6 @@ def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_r
|
||||
})
|
||||
return node_records, link_records
|
||||
|
||||
influxdb_cache = {}
|
||||
|
||||
# 2025/02/21 WMH
|
||||
def query_all_record_by_date_property(query_date: str, type: str, property: str,
|
||||
bucket: str="realtime_simulation_result", client: InfluxDBClient=client) -> list:
|
||||
@@ -1857,12 +1847,6 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
|
||||
:return: list(dict): result_records
|
||||
"""
|
||||
|
||||
global influxdb_cache
|
||||
|
||||
cache_key = f"{query_date}_{type}_{property}"
|
||||
if influxdb_cache.get(cache_key) is not None:
|
||||
return influxdb_cache.get(cache_key)
|
||||
|
||||
if client.ping(): print("{} -- Successfully connected to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
||||
else: print("{} -- Failed to connect to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
||||
|
||||
@@ -1913,8 +1897,6 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
|
||||
property: record["_value"]
|
||||
})
|
||||
|
||||
influxdb_cache[cache_key] = result_records
|
||||
|
||||
return result_records
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user