RefreshChat synchronously refreshes a single chat's diff status using the same Refresher pipeline as the background worker. Returns nil, nil when no PR exists yet for the branch. Called from HTTP handlers for instant feedback.
( ctx context.Context, row database.ChatDiffStatus, ownerID uuid.UUID, )
| 359 | // worker. Returns nil, nil when no PR exists yet for the |
| 360 | // branch. Called from HTTP handlers for instant feedback. |
| 361 | func (w *Worker) RefreshChat( |
| 362 | ctx context.Context, |
| 363 | row database.ChatDiffStatus, |
| 364 | ownerID uuid.UUID, |
| 365 | ) (*database.ChatDiffStatus, error) { |
| 366 | requests := []RefreshRequest{{ |
| 367 | Row: row, |
| 368 | OwnerID: ownerID, |
| 369 | }} |
| 370 | |
| 371 | results, err := w.refresher.Refresh(ctx, requests) |
| 372 | if err != nil { |
| 373 | return nil, xerrors.Errorf("refresh chat diff status: %w", err) |
| 374 | } |
| 375 | |
| 376 | if len(results) == 0 { |
| 377 | return nil, nil |
| 378 | } |
| 379 | res := results[0] |
| 380 | if res.Error != nil { |
| 381 | return nil, xerrors.Errorf("refresh chat diff status: %w", res.Error) |
| 382 | } |
| 383 | if res.Params == nil { |
| 384 | return nil, nil |
| 385 | } |
| 386 | |
| 387 | upserted, err := w.store.UpsertChatDiffStatus(ctx, *res.Params) |
| 388 | if err != nil { |
| 389 | return nil, xerrors.Errorf("upsert chat diff status: %w", err) |
| 390 | } |
| 391 | |
| 392 | if w.publishDiffStatusChangeFn != nil { |
| 393 | if err := w.publishDiffStatusChangeFn(ctx, row.ChatID); err != nil { |
| 394 | w.logger.Debug(ctx, "publish diff status change", |
| 395 | slog.F("chat_id", row.ChatID), |
| 396 | slog.Error(err)) |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | return &upserted, nil |
| 401 | } |