Cache getnetworkgeometries
This commit is contained in:
23
main.py
23
main.py
@@ -1611,6 +1611,15 @@ async def fastapi_get_node_coord(network: str, node: str) -> dict[str, float] |
|
||||
# link type: pipe, pump, valve
|
||||
@app.get("/getnetworkgeometries/")
|
||||
async def fastapi_get_network_geometries(network: str) -> dict[str, Any] | None:
|
||||
# 获取所有节点坐标# 缓存查询结果提高性能
|
||||
global redis_client
|
||||
cache_key = f"getnetworkgeometries_{network}"
|
||||
data = redis_client.get(cache_key)
|
||||
if data:
|
||||
# 使用自定义的反序列化函数
|
||||
loaded_dict = msgpack.unpackb(data, object_hook=object_hook)
|
||||
return loaded_dict
|
||||
|
||||
coords = get_network_node_coords(network)
|
||||
nodes = []
|
||||
for node_id, coord in coords.items():
|
||||
@@ -1623,10 +1632,15 @@ async def fastapi_get_network_geometries(network: str) -> dict[str, Any] | None:
|
||||
# data from WMH's scada info
|
||||
scadas = get_all_scada_info(network)
|
||||
|
||||
return { 'nodes': nodes,
|
||||
results = { 'nodes': nodes,
|
||||
'links': links,
|
||||
'scadas': scadas }
|
||||
|
||||
# 缓存查询结果提高性能
|
||||
redis_client.set(cache_key, msgpack.packb(results, default=object_hook))
|
||||
|
||||
return results
|
||||
|
||||
# DingZQ, 2024-12-31, get major node coord
|
||||
# id:type:x:y
|
||||
# type: junction, reservoir, tank
|
||||
@@ -2237,9 +2251,13 @@ async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]:
|
||||
return loaded_dict
|
||||
|
||||
nodes_links: tuple = influxdb_api.query_all_record_by_date(query_date=querydate)
|
||||
return { "nodes": nodes_links[0],
|
||||
results = { "nodes": nodes_links[0],
|
||||
"links": nodes_links[1] }
|
||||
|
||||
redis_client.set(cache_key, msgpack.packb(results, default=object_hook))
|
||||
|
||||
return results
|
||||
|
||||
#2025-03-15, DingZQ
|
||||
@app.get("/queryallrecordsbydatewithtype/")
|
||||
async def fastapi_query_all_records_by_date_with_type(querydate: str, querytype: str) -> list:
|
||||
@@ -2253,6 +2271,7 @@ async def fastapi_query_all_records_by_date_with_type(querydate: str, querytype:
|
||||
return loaded_dict
|
||||
|
||||
results = influxdb_api.query_all_records_by_date_with_type(query_date=querydate, query_type=querytype)
|
||||
|
||||
packed = msgpack.packb(results, default=default_encoder)
|
||||
redis_client.set(cache_key, packed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user