Skip to content

Commit

Permalink
feat: limit batch id to 0~32767
Browse files Browse the repository at this point in the history
  • Loading branch information
JamzumSum committed Sep 2, 2023
1 parent dfae6d5 commit 5cc6e96
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
14 changes: 7 additions & 7 deletions doc/source/locale/zh_CN/LC_MESSAGES/api/feed.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: aioqzone-feed \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-08-10 14:10+0800\n"
"POT-Creation-Date: 2023-09-02 09:22+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: zh_CN\n"
Expand Down Expand Up @@ -131,8 +131,10 @@ msgstr ""

#: aioqzone_feed.api.feed.h5.FeedH5Api.get_feeds_by_count:12
#: aioqzone_feed.api.feed.h5.FeedH5Api.get_feeds_by_second:15
#: aioqzone_feed.api.feed.h5.FeedH5Api.new_batch:5
#: aioqzone_feed.api.feed.web.FeedWebApi.get_feeds_by_count:12
#: aioqzone_feed.api.feed.web.FeedWebApi.get_feeds_by_second:15 of
#: aioqzone_feed.api.feed.web.FeedWebApi.get_feeds_by_second:15
#: aioqzone_feed.api.feed.web.FeedWebApi.new_batch:5 of
msgid ":py:class:`int`"
msgstr ""

Expand Down Expand Up @@ -188,11 +190,6 @@ msgid ""
"`(bid, uin, abstime)`."
msgstr ""

#: aioqzone_feed.api.feed.h5.FeedH5Api.new_batch:5 aioqzone_feed.api.feed.web.FeedWebApi.new_batch:5
#: of
msgid ":obj:`TY_BID`"
msgstr ""

#: aioqzone_feed.api.feed.h5.FeedH5Api.new_batch:6 aioqzone_feed.api.feed.web.FeedWebApi.new_batch:6
#: of
msgid "The batch_id."
Expand Down Expand Up @@ -233,3 +230,6 @@ msgstr ""

#~ msgid ":obj:`FeedEvent.TY_BID`"
#~ msgstr ""

#~ msgid ":obj:`TY_BID`"
#~ msgstr ""
9 changes: 4 additions & 5 deletions doc/source/locale/zh_CN/LC_MESSAGES/message/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: aioqzone-feed \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-08-10 14:17+0800\n"
"POT-Creation-Date: 2023-09-02 09:22+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: zh_CN\n"
Expand Down Expand Up @@ -51,10 +51,6 @@ msgstr ""
msgid ":py:class:`bool`"
msgstr ""

#: builtins.int:1 of
msgid "Batch ID type. Currently it is a `int`."
msgstr ""

#: ../../docstring aioqzone_feed.message.feed.processed_feed.bid:1
#: aioqzone_feed.message.feed.raw_feed.bid:1 of
msgid "Used to identify feed batch (tell from different calling)."
Expand Down Expand Up @@ -98,3 +94,6 @@ msgstr ""

#~ msgid "aioqzone-feed Events"
#~ msgstr ""

#~ msgid "Batch ID type. Currently it is a `int`."
#~ msgstr ""
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aioqzone-feed"
version = "0.14.0.dev5"
version = "0.14.1.dev1"
description = "aioqzone plugin providing higher level api for processing feed."
authors = ["aioqzone <[email protected]>"]
license = "AGPL-3.0"
Expand Down
11 changes: 7 additions & 4 deletions src/aioqzone_feed/api/feed/h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

from aioqzone_feed.api.heartbeat import HeartbeatApi
from aioqzone_feed.message import FeedApiEmitterMixin
from aioqzone_feed.message.feed import TY_BID
from aioqzone_feed.type import FeedContent
from aioqzone_feed.utils.exc_barrier import ExcBarrier

log = logging.getLogger(__name__)
login_exc = (LoginError, UserBreak, asyncio.CancelledError)
MAX_BID = 0x7FFF
"""The max batch id.
.. versionadded:: 0.14.1
"""


class FeedH5Api(FeedApiEmitterMixin[FeedData], QzoneH5API):
Expand All @@ -32,17 +36,16 @@ def __init__(self, client: ClientAdapter, loginman: Loginable, *, init_hb=True):
if init_hb:
self.hb_api = HeartbeatApi(self)

def new_batch(self) -> TY_BID:
def new_batch(self) -> int:
"""
The new_batch function edit internal batch id and return it.
A batch id can be used to identify a batch, thus even the same feed can have different id e.g. `(bid, uin, abstime)`.
:rtype: :obj:`TY_BID`
:return: The batch_id.
"""

self.bid += 1
self.bid = (self.bid + 1) % MAX_BID
return self.bid

async def get_feeds_by_count(self, count: int = 10) -> int:
Expand Down
11 changes: 7 additions & 4 deletions src/aioqzone_feed/api/feed/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

from aioqzone_feed.api.heartbeat import HeartbeatApi
from aioqzone_feed.message import FeedApiEmitterMixin
from aioqzone_feed.message.feed import TY_BID
from aioqzone_feed.type import FeedContent, VisualMedia
from aioqzone_feed.utils.exc_barrier import ExcBarrier

log = logging.getLogger(__name__)
login_exc = (LoginError, UserBreak, asyncio.CancelledError)
MAX_BID = 0x7FFF
"""The max batch id.
.. versionadded:: 0.14.1
"""

T = TypeVar("T")

Expand Down Expand Up @@ -80,17 +84,16 @@ def __init__(self, client: ClientAdapter, loginman: Loginable, *, init_hb=True):
if init_hb:
self.hb_api = HeartbeatApi(self)

def new_batch(self) -> TY_BID:
def new_batch(self) -> int:
"""
The new_batch function edit internal batch id and return it.
A batch id can be used to identify a batch, thus even the same feed can have different id e.g. `(bid, uin, abstime)`.
:rtype: :obj:`TY_BID`
:return: The batch_id.
"""

self.bid += 1
self.bid = (self.bid + 1) % MAX_BID
return self.bid

async def get_feeds_by_count(self, count: int = 10) -> int:
Expand Down
8 changes: 3 additions & 5 deletions src/aioqzone_feed/message/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@
from aioqzone_feed.type import BaseFeed, FeedContent

_F = TypeVar("_F", FeedData, FeedRep)
TY_BID = int
"""Batch ID type. Currently it is a `int`."""

__all__ = ["raw_feed", "processed_feed", "FeedApiEmitterMixin", "TY_BID"]
__all__ = ["raw_feed", "processed_feed", "FeedApiEmitterMixin"]


@dataclass
class raw_feed(BaseMessage):
bid: TY_BID
bid: int
"""Used to identify feed batch (tell from different calling)."""
feed: BaseFeed
"""Used to pass a ref to the feed."""


@dataclass
class processed_feed(BaseMessage):
bid: TY_BID
bid: int
"""Used to identify feed batch (tell from different calling)."""
feed: FeedContent
"""Used to pass the feed content."""
Expand Down

0 comments on commit 5cc6e96

Please sign in to comment.