This commit is contained in:
DingZQ
2025-03-22 13:26:25 +08:00
parent ea09d71604
commit 434805029b
2 changed files with 25 additions and 3 deletions

15
main.py
View File

@@ -2144,9 +2144,18 @@ async def fastapi_query_all_records_by_time(querytime: str) -> dict[str, list]:
#def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_result", client: InfluxDBClient=client) -> tuple:
@app.get("/queryallrecordsbydate/")
async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]:
results: tuple = influxdb_api.query_all_record_by_date(query_date=querydate, client=influx_client)
return { "nodes": results[0],
"links": results[1] }
# 缓存查询结果提高性能
global redis_client
cache_key = f"queryallrecordsbydate_{querydate}"
data = redis_client.get(cache_key)
if data:
# 使用自定义的反序列化函数
loaded_dict = msgpack.unpackb(data, object_hook=object_hook)
return loaded_dict
nodes_links: tuple = influxdb_api.query_all_record_by_date(query_date=querydate, client=influx_client)
return { "nodes": nodes_links[0],
"links": nodes_links[1] }
#2025-03-15, DingZQ
@app.get("/queryallrecordsbydatewithtype/")