feat: 配置列表分页与钉钉机器人分钟级排队限流
统一 sources/templates/channels/rules 列表为分页响应,避免配置增多时全量返回;按钉钉 access_token 限制每分钟发送并在超限时等待下一分钟,降低触发官方封禁风险。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -54,13 +54,19 @@ func (s *Store) GetSourceByName(ctx context.Context, name string) (*model.Source
|
||||
return &src, nil
|
||||
}
|
||||
|
||||
func (s *Store) ListSources(ctx context.Context) ([]model.Source, error) {
|
||||
sources := make([]model.Source, 0)
|
||||
err := s.DB.SelectContext(ctx, &sources, `SELECT * FROM notification_source ORDER BY id`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list sources: %w", err)
|
||||
func (s *Store) ListSources(ctx context.Context, page PageFilter) ([]model.Source, int, error) {
|
||||
var count int
|
||||
if err := s.DB.GetContext(ctx, &count, `SELECT COUNT(*) FROM notification_source`); err != nil {
|
||||
return nil, 0, fmt.Errorf("count sources: %w", err)
|
||||
}
|
||||
return sources, nil
|
||||
|
||||
page.Normalize()
|
||||
sources := make([]model.Source, 0)
|
||||
err := s.DB.SelectContext(ctx, &sources, `SELECT * FROM notification_source ORDER BY id LIMIT ? OFFSET ?`, page.PageSize, page.Offset())
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("list sources: %w", err)
|
||||
}
|
||||
return sources, count, nil
|
||||
}
|
||||
|
||||
func (s *Store) UpdateSource(ctx context.Context, id int, src *model.Source) error {
|
||||
|
||||
Reference in New Issue
Block a user