-
Notifications
You must be signed in to change notification settings - Fork 239
修改群修改topic后,本地缓存未更新的bug #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
675c667
7cba0c8
43ea5ef
f537071
bc79fd3
0f777cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -167,9 +167,10 @@ def filter_func(room: Room) -> bool: | |||||||||||||||||||||||||||||||||||||||||||||
payload = room.payload | ||||||||||||||||||||||||||||||||||||||||||||||
if not payload: | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
if query == payload.id or (query.lower() in payload.topic.lower()): # type: ignore | ||||||||||||||||||||||||||||||||||||||||||||||
if query == payload.id or (query.lower() in payload.topic.lower()): # type: ignore | ||||||||||||||||||||||||||||||||||||||||||||||
return True | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
func = filter_func | ||||||||||||||||||||||||||||||||||||||||||||||
elif isinstance(query, RoomQueryFilter): | ||||||||||||||||||||||||||||||||||||||||||||||
def filter_func(room: Room) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -179,9 +180,10 @@ def filter_func(room: Room) -> bool: | |||||||||||||||||||||||||||||||||||||||||||||
if not payload: | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if query.id == payload.id or (query.topic.lower() in payload.topic.lower()): # noqa | ||||||||||||||||||||||||||||||||||||||||||||||
if query.id == payload.id or (query.topic.lower() in payload.topic.lower()): # noqa | ||||||||||||||||||||||||||||||||||||||||||||||
return True | ||||||||||||||||||||||||||||||||||||||||||||||
return False | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
func = filter_func | ||||||||||||||||||||||||||||||||||||||||||||||
elif isinstance(query, types.FunctionType): | ||||||||||||||||||||||||||||||||||||||||||||||
func = query | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -230,7 +232,7 @@ async def find_all(cls, | |||||||||||||||||||||||||||||||||||||||||||||
rooms: List[Room] = [cls.load(room_id) for room_id in room_ids] | ||||||||||||||||||||||||||||||||||||||||||||||
tasks: List[Task] = [asyncio.create_task(room.ready()) for room in rooms] | ||||||||||||||||||||||||||||||||||||||||||||||
await gather_with_concurrency(PARALLEL_TASK_NUM, tasks) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
# 2. filter the rooms | ||||||||||||||||||||||||||||||||||||||||||||||
if not query: | ||||||||||||||||||||||||||||||||||||||||||||||
return rooms | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -290,6 +292,15 @@ def load(cls, room_id: str) -> Room: | |||||||||||||||||||||||||||||||||||||||||||||
cls._pool[room_id] = room | ||||||||||||||||||||||||||||||||||||||||||||||
return room | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||||||||||||||||||||||||||
def upload_cache(cls, room_id: str)->None: | ||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||
dynamic upload | ||||||||||||||||||||||||||||||||||||||||||||||
clear the room_id of _pool and upload it use load | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a wording issue in the docstring: "clear the room_id of _pool and upload it use load". Consider rephrasing it to something like "clear the room_id from _pool and re-upload it using load", to improve clarity.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||
cls._pool[room_id] = None | ||||||||||||||||||||||||||||||||||||||||||||||
cls.load(room_id) | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve the The current implementation has several issues:
Apply this diff to improve the method: @classmethod
-def upload_cache(cls, room_id: str)->None:
+def refresh_cache(cls, room_id: str) -> 'Room':
"""
- dynamic upload
- clear the room_id of _pool and upload it use load
+ Refresh the cached room instance by clearing and reloading it.
+
+ Args:
+ room_id: The room ID to refresh
+
+ Returns:
+ Room: The refreshed room instance
"""
- cls._pool[room_id] = None
- cls.load(room_id)
+ if room_id in cls._pool:
+ del cls._pool[room_id]
+ return cls.load(room_id) Note: If you rename this method, also update the call in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
def __str__(self) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||
string format for room instance | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -349,7 +360,7 @@ async def ready(self, force_sync: bool = False, load_members: bool = False) -> N | |||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
async def say(self, | ||||||||||||||||||||||||||||||||||||||||||||||
some_thing: Union[str, Contact, | ||||||||||||||||||||||||||||||||||||||||||||||
FileBox, MiniProgram, UrlLink], | ||||||||||||||||||||||||||||||||||||||||||||||
FileBox, MiniProgram, UrlLink], | ||||||||||||||||||||||||||||||||||||||||||||||
mention_ids: Optional[List[str]] = None | ||||||||||||||||||||||||||||||||||||||||||||||
) -> Union[None, Message]: | ||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.