fix: incorrect use asyncio.thread -> remove
This commit is contained in:
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import json
|
import json
|
||||||
import asyncio
|
|
||||||
from async_lru import alru_cache
|
from async_lru import alru_cache
|
||||||
|
|
||||||
router = APIRouter(prefix='/api/v1', tags=['tariffs'])
|
router = APIRouter(prefix='/api/v1', tags=['tariffs'])
|
||||||
@@ -10,7 +9,7 @@ router = APIRouter(prefix='/api/v1', tags=['tariffs'])
|
|||||||
async def get_tariffs_from_file():
|
async def get_tariffs_from_file():
|
||||||
async with aiofiles.open('data/tariffs.json', 'r', encoding='utf-8') as f:
|
async with aiofiles.open('data/tariffs.json', 'r', encoding='utf-8') as f:
|
||||||
content = await f.read()
|
content = await f.read()
|
||||||
return await asyncio.to_thread(json.loads(content))
|
return json.loads(content) # <- блокирующая операция, но с маленьким контентом + кэш
|
||||||
|
|
||||||
@router.get('/tariffs')
|
@router.get('/tariffs')
|
||||||
async def get_tariffs():
|
async def get_tariffs():
|
||||||
|
|||||||
Reference in New Issue
Block a user