-
Notifications
You must be signed in to change notification settings - Fork 610
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
🐛 修复获取群组时会修改群组插件关闭状态 #1869
base: main
Are you sure you want to change the base?
🐛 修复获取群组时会修改群组插件关闭状态 #1869
Conversation
## Sourcery 评审者指南
此拉取请求解决了一个 bug,该 bug 导致检索组信息时意外修改了禁用的插件状态。它还改进了帮助图片的删除,并更新了用于设置插件状态的消息。此修复包括修改插件查询以包含 `load_status=True`,并更新帮助图片删除逻辑。
#### GroupConsole.get_or_create 的序列图
```mermaid
sequenceDiagram
participant GroupConsole
participant TaskInfo
participant PluginInfo
GroupConsole->>TaskInfo: filter(default_status=False).values_list("module", flat=True)
TaskInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_task = ...
end
GroupConsole->>PluginInfo: filter(plugin_type__in=[...], default_status=False, load_status=True).values_list("module", flat=True)
PluginInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_plugin = ...
end
GroupConsole->>GroupConsole: group.save(update_fields=["block_plugin", "block_task"]) GroupConsole.update_or_create 的序列图sequenceDiagram
participant GroupConsole
participant TaskInfo
participant PluginInfo
GroupConsole->>TaskInfo: filter(default_status=False).values_list("module", flat=True)
TaskInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_task = ...
end
GroupConsole->>PluginInfo: filter(plugin_type__in=[...], default_status=False, load_status=True).values_list("module", flat=True)
PluginInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_plugin = ...
end
GroupConsole->>GroupConsole: group.save(update_fields=["block_plugin", "block_task"])
文件级别变更
提示和命令与 Sourcery 交互
自定义您的体验访问您的 仪表板 以:
获得帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request addresses a bug where retrieving group information inadvertently modified the disabled plugin state. It also improves the deletion of help images and updates messages for setting plugin statuses. The fix involves modifying the query for plugins to include Sequence diagram for GroupConsole.get_or_createsequenceDiagram
participant GroupConsole
participant TaskInfo
participant PluginInfo
GroupConsole->>TaskInfo: filter(default_status=False).values_list("module", flat=True)
TaskInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_task = ...
end
GroupConsole->>PluginInfo: filter(plugin_type__in=[...], default_status=False, load_status=True).values_list("module", flat=True)
PluginInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_plugin = ...
end
GroupConsole->>GroupConsole: group.save(update_fields=["block_plugin", "block_task"])
Sequence diagram for GroupConsole.update_or_createsequenceDiagram
participant GroupConsole
participant TaskInfo
participant PluginInfo
GroupConsole->>TaskInfo: filter(default_status=False).values_list("module", flat=True)
TaskInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_task = ...
end
GroupConsole->>PluginInfo: filter(plugin_type__in=[...], default_status=False, load_status=True).values_list("module", flat=True)
PluginInfo-->>GroupConsole: modules
alt modules is not empty
GroupConsole->>GroupConsole: convert_module_format(modules)
GroupConsole->>GroupConsole: group.block_plugin = ...
end
GroupConsole->>GroupConsole: group.save(update_fields=["block_plugin", "block_task"])
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @HibiKier - I've reviewed your changes - here's some feedback:
Overall Comments:
- The logic in
get_or_create
andupdate_or_create
is very similar; consider refactoring to reduce duplication.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
for file in os.listdir(GROUP_HELP_PATH): | ||
if file.startswith(f"{gid}"): | ||
os.remove(GROUP_HELP_PATH / file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using Pathlib methods for file operations.
Since GROUP_HELP_PATH appears to be a Path object, you could use GROUP_HELP_PATH.glob(...) and then call unlink() on each file for better consistency and readability, instead of mixing os.listdir with os.remove.
for file in os.listdir(GROUP_HELP_PATH): | |
if file.startswith(f"{gid}"): | |
os.remove(GROUP_HELP_PATH / file) | |
for file in GROUP_HELP_PATH.glob(f"{gid}*"): | |
file.unlink() |
@@ -110,17 +110,17 @@ async def get_or_create( | |||
group, is_create = await super().get_or_create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider extracting the block-setting code into a helper function to reduce nesting and duplication in get_or_create
and update_or_create
methods, improving readability and maintainability.
You can reduce nesting and duplicate logic by extracting the block–setting code into a helper. This flattens the conditionals and makes both get_or_create
and update_or_create
easier to read. For example:
@classmethod
async def update_block_fields(cls, group, load_status: bool):
# Retrieve and set task modules
task_modules = await TaskInfo.filter(default_status=False).values_list("module", flat=True)
if task_modules:
group.block_task = cls.convert_module_format(task_modules)
# Retrieve and set plugin modules; load_status is applied only if True.
plugin_filter = dict(
plugin_type__in=[PluginType.NORMAL, PluginType.DEPENDANT],
default_status=False,
)
if load_status:
plugin_filter["load_status"] = True
plugin_modules = await PluginInfo.filter(**plugin_filter).values_list("module", flat=True)
if plugin_modules:
group.block_plugin = cls.convert_module_format(plugin_modules)
Then in your methods use an early check:
async def get_or_create(cls, defaults: dict | None = None, using_db: BaseDBAsyncClient | None = None, **kwargs: Any) -> tuple[Self, bool]:
group, is_create = await super().get_or_create(defaults=defaults, using_db=using_db, **kwargs)
if is_create:
await cls.update_block_fields(group, load_status=True)
await group.save(using_db=using_db, update_fields=["block_plugin", "block_task"])
return group, is_create
@classmethod
async def update_or_create(cls, defaults: dict | None = None, using_db: BaseDBAsyncClient | None = None, **kwargs: Any) -> tuple[Self, bool]:
group, is_create = await super().update_or_create(defaults=defaults, using_db=using_db, **kwargs)
if is_create:
await cls.update_block_fields(group, load_status=True)
await group.save(using_db=using_db, update_fields=["block_plugin", "block_task"])
return group, is_create
This approach keeps all functionality intact while reducing the complexity from nested conditionals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
阿咪合一下pr
No description provided.