Skip to content

Commit

Permalink
perf: 使用 msgspec 进行 JSON 编码以提升性能
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Jan 26, 2025
1 parent 2977f08 commit aeb400a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions jkit/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from typing import Any, Literal, overload

from httpx import AsyncClient
from msgspec.json import Decoder
from msgspec.json import Decoder as JsonDecoder
from msgspec.json import Encoder as JsonEncoder

from jkit.config import CONFIG

JSON_DECODER = Decoder()
JSON_ENCODER = JsonEncoder()
JSON_DECODER = JsonDecoder()

DatasourceType = Literal["JIANSHU", "JPEP"]

Expand Down Expand Up @@ -72,7 +74,7 @@ async def send_request( # noqa: PLR0913
method=method,
url=path,
params=params,
json=body,
content=JSON_ENCODER.encode(body) if body else None,
headers={
"Accpet": "text/html" if response_type == "HTML" else "application/json"
},
Expand Down

0 comments on commit aeb400a

Please sign in to comment.