feat: 配置列表分页与钉钉机器人分钟级排队限流

统一 sources/templates/channels/rules 列表为分页响应,避免配置增多时全量返回;按钉钉 access_token 限制每分钟发送并在超限时等待下一分钟,降低触发官方封禁风险。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-10 00:34:26 +08:00
parent 009694fee7
commit 39f3774940
27 changed files with 1447 additions and 60 deletions
+12 -6
View File
@@ -36,13 +36,19 @@ func (s *Store) GetTemplateByName(ctx context.Context, name string) (*model.Temp
return &t, nil
}
func (s *Store) ListTemplates(ctx context.Context) ([]model.Template, error) {
templates := make([]model.Template, 0)
err := s.DB.SelectContext(ctx, &templates, `SELECT * FROM notification_template ORDER BY id`)
if err != nil {
return nil, fmt.Errorf("list templates: %w", err)
func (s *Store) ListTemplates(ctx context.Context, page PageFilter) ([]model.Template, int, error) {
var count int
if err := s.DB.GetContext(ctx, &count, `SELECT COUNT(*) FROM notification_template`); err != nil {
return nil, 0, fmt.Errorf("count templates: %w", err)
}
return templates, nil
page.Normalize()
templates := make([]model.Template, 0)
err := s.DB.SelectContext(ctx, &templates, `SELECT * FROM notification_template ORDER BY id LIMIT ? OFFSET ?`, page.PageSize, page.Offset())
if err != nil {
return nil, 0, fmt.Errorf("list templates: %w", err)
}
return templates, count, nil
}
func (s *Store) UpdateTemplate(ctx context.Context, id int, t *model.Template) error {