Refine
This commit is contained in:
19
main.py
19
main.py
@@ -24,6 +24,7 @@ from datetime import datetime, timedelta, timezone
|
||||
from dateutil import parser
|
||||
import influxdb_info
|
||||
import influxdb_api
|
||||
import py_linq
|
||||
|
||||
JUNCTION = 0
|
||||
RESERVOIR = 1
|
||||
@@ -2165,7 +2166,25 @@ async def fastapi_query_all_records_by_date_with_type(querydate: str, querytype:
|
||||
|
||||
return results
|
||||
|
||||
@app.get("/queryallrecordsbydatewithtype/")
|
||||
async def fastapi_query_all_records_by_ids_date_type(ids:str, querydate: str, querytype: str) -> list:
|
||||
# 缓存查询结果提高性能
|
||||
global redis_client
|
||||
cache_key = f"queryallrecordsbydatewithtype_{querydate}_{querytype}"
|
||||
data = redis_client.get(cache_key)
|
||||
if data:
|
||||
# 使用自定义的反序列化函数
|
||||
loaded_dict = msgpack.unpackb(data, object_hook=object_hook)
|
||||
return loaded_dict
|
||||
|
||||
results = influxdb_api.query_all_records_by_date_with_type(query_date=querydate, query_type=querytype, client=influx_client)
|
||||
packed = msgpack.packb(results, default=default_encoder)
|
||||
redis_client.set(cache_key, packed)
|
||||
|
||||
query_ids = ids.split(",")
|
||||
e_results = py_linq.Enumerable(results)
|
||||
|
||||
return e_results.where(lambda x: x.ID in query_ids).to_list()
|
||||
|
||||
|
||||
# 查询指定日期、类型、属性的所有记录
|
||||
|
||||
Reference in New Issue
Block a user