mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 00:46:57 +08:00
feat(recommend): add semaphore to limit concurrent requests
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
from typing import Any, List, Dict
|
from typing import Any, List, Dict
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
@@ -42,8 +43,12 @@ def play_item(itemid: str, _: schemas.TokenPayload = Depends(verify_token)) -> s
|
|||||||
return schemas.Response(success=False, message="未找到播放地址")
|
return schemas.Response(success=False, message="未找到播放地址")
|
||||||
|
|
||||||
|
|
||||||
|
# 控制最大并发数
|
||||||
|
semaphore = asyncio.Semaphore(10)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/exists", summary="查询本地是否存在(数据库)", response_model=schemas.Response)
|
@router.get("/exists", summary="查询本地是否存在(数据库)", response_model=schemas.Response)
|
||||||
def exists_local(title: str = None,
|
async def exists_local(title: str = None,
|
||||||
year: int = None,
|
year: int = None,
|
||||||
mtype: str = None,
|
mtype: str = None,
|
||||||
tmdbid: int = None,
|
tmdbid: int = None,
|
||||||
@@ -53,6 +58,7 @@ def exists_local(title: str = None,
|
|||||||
"""
|
"""
|
||||||
判断本地是否存在
|
判断本地是否存在
|
||||||
"""
|
"""
|
||||||
|
async with semaphore:
|
||||||
meta = MetaInfo(title)
|
meta = MetaInfo(title)
|
||||||
if not season:
|
if not season:
|
||||||
season = meta.begin_season
|
season = meta.begin_season
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
|
||||||
import cn2an
|
import cn2an
|
||||||
@@ -146,8 +147,12 @@ def update_subscribe_status(
|
|||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
|
# 控制最大并发数
|
||||||
|
semaphore = asyncio.Semaphore(10)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/media/{mediaid}", summary="查询订阅", response_model=schemas.Subscribe)
|
@router.get("/media/{mediaid}", summary="查询订阅", response_model=schemas.Subscribe)
|
||||||
def subscribe_mediaid(
|
async def subscribe_mediaid(
|
||||||
mediaid: str,
|
mediaid: str,
|
||||||
season: int = None,
|
season: int = None,
|
||||||
title: str = None,
|
title: str = None,
|
||||||
@@ -156,6 +161,7 @@ def subscribe_mediaid(
|
|||||||
"""
|
"""
|
||||||
根据 TMDBID/豆瓣ID/BangumiId 查询订阅 tmdb:/douban:
|
根据 TMDBID/豆瓣ID/BangumiId 查询订阅 tmdb:/douban:
|
||||||
"""
|
"""
|
||||||
|
async with semaphore:
|
||||||
result = None
|
result = None
|
||||||
title_check = False
|
title_check = False
|
||||||
if mediaid.startswith("tmdb:"):
|
if mediaid.startswith("tmdb:"):
|
||||||
|
|||||||
Reference in New Issue
Block a user