✨ 首次启动时提供使用web ui方式完全配置#1870
Conversation
Sourcery 审查者指南此 Pull Request 引入了一个 Web UI 配置,用于在数据库 URL 未配置时的初始设置。它还实现了一个新的 启动时 Hook 优先级管理的时序图sequenceDiagram
participant Driver
participant HookPriorityManager
Driver->>HookPriorityManager: on_startup()
activate HookPriorityManager
HookPriorityManager->>HookPriorityManager: Get priority data for STARTUP
HookPriorityManager->>HookPriorityManager: Sort priorities
loop For each priority
loop For each function in priority
HookPriorityManager->>func: Call function
activate func
func-->>HookPriorityManager: Return
deactivate func
end
end
deactivate HookPriorityManager
HookPriorityManager 的更新类图classDiagram
class HookPriorityManager {
_data: dict[HookPriorityType, dict[int, list[Callable]]]
+add(hook_type: HookPriorityType, func: Callable, priority: int = 5)
+on_startup(priority: int = 5)
+on_shutdown(priority: int = 5)
}
class HookPriorityType {
STARTUP = \"STARTUP\"
SHUTDOWN = \"SHUTDOWN\"
}
HookPriorityManager -- HookPriorityType : Uses
文件级别变更
提示和命令与 Sourcery 互动
自定义您的体验访问您的 仪表板 以:
获得帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request introduces a web UI configuration for initial setup when the database URL is not configured. It also implements a new Sequence diagram for Hook Priority Management on StartupsequenceDiagram
participant Driver
participant HookPriorityManager
Driver->>HookPriorityManager: on_startup()
activate HookPriorityManager
HookPriorityManager->>HookPriorityManager: Get priority data for STARTUP
HookPriorityManager->>HookPriorityManager: Sort priorities
loop For each priority
loop For each function in priority
HookPriorityManager->>func: Call function
activate func
func-->>HookPriorityManager: Return
deactivate func
end
end
deactivate HookPriorityManager
Updated class diagram for HookPriorityManagerclassDiagram
class HookPriorityManager {
_data: dict[HookPriorityType, dict[int, list[Callable]]]
+add(hook_type: HookPriorityType, func: Callable, priority: int = 5)
+on_startup(priority: int = 5)
+on_shutdown(priority: int = 5)
}
class HookPriorityType {
STARTUP = \"STARTUP\"
SHUTDOWN = \"SHUTDOWN\"
}
HookPriorityManager -- HookPriorityType : Uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @HibiKier - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a more descriptive name than
_for functions decorated with@HookPriorityManager.on_startup. - The
HookPriorityExceptionseems like it's being used for control flow; consider if there's a better way to handle the initial configuration.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 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.
| driver = nonebot.get_driver() | ||
|
|
||
|
|
||
| class HookPriorityManager: |
There was a problem hiding this comment.
issue (complexity): Consider using a list of (priority, callable) tuples instead of a nested dictionary for hook management to simplify registration and execution if the prioritization feature is used in a few places only .
If the prioritization feature is only used in a few places, you might reduce the complexity by switching from a nested dictionary to a simple per–hook-type list of (priority, callable) tuples. This simplifies both registration and execution. For example:
Before:
```python
class HookPriorityManager:
_data: ClassVar[dict[HookPriorityType, dict[int, list[Callable]]]] = {}
@classmethod
def add(cls, hook_type: HookPriorityType, func: Callable, priority: int = 5):
if hook_type not in cls._data:
cls._data[hook_type] = {}
if priority not in cls._data[hook_type]:
cls._data[hook_type][priority] = []
cls._data[hook_type][priority].append(func)After:
class HookPriorityManager:
_data: ClassVar[dict[HookPriorityType, list[tuple[int, Callable]]]] = {}
@classmethod
def add(cls, hook_type: HookPriorityType, func: Callable, priority: int = 5):
cls._data.setdefault(hook_type, []).append((priority, func))
@classmethod
async def run_hooks(cls, hook_type: HookPriorityType):
hooks = cls._data.get(hook_type, [])
for prio, func in sorted(hooks, key=lambda x: x[0]):
if is_coroutine_callable(func):
await func()
else:
func()Then update the startup handler to call this method:
@driver.on_startup
async def _():
try:
await HookPriorityManager.run_hooks(HookPriorityType.STARTUP)
except HookPriorityException as e:
logger.error(f"HookExecution interrupted: {e}")This keeps all functionality intact while reducing the layers of nested dictionaries and making registration/execution logic simpler to follow.
4ff0540 to
e84fc89
Compare
…enxun_bot into feature/webui-config
No description provided.