fix(web): правки применяются сразу и не сбрасывают вкладку

Вкладка «Редактирование» больше не переключается на «Сведения» при
обновлении того же фото: временное состояние панели сбрасывается только при
смене фото.

Правки теперь рендерятся без ожидания тика воркера: сервис будит воркер сразу
после постановки задачи, а уведомление о готовых вариантах приходит до
кодирования полноразмерной версии. Задержка между сохранением правок и
появлением отредактированной версии — около 0.25 с вместо нескольких секунд.
This commit is contained in:
iu
2026-10-20 23:11:57 +03:00
parent 0548b1ab5e
commit cd3d17c0f0
8 changed files with 87 additions and 27 deletions
+27 -2
View File
@@ -41,6 +41,9 @@ type Worker struct {
videoConc int
videoLease time.Duration
tempDir string
// wake будит воркер немедленно, чтобы свежие правки не ждали тика.
wake chan struct{}
}
// NewWorker builds a worker. Parameters are clamped to sane defaults.
@@ -66,6 +69,19 @@ func NewWorker(svc *Service, interval time.Duration, batch int, pendingTTL time.
concurrency: concurrency,
videoConc: 1,
videoLease: videoJobLease,
wake: make(chan struct{}, 1),
}
}
// Wake asks the worker to process the queues right away instead of waiting for
// the next tick. It is safe to call from any goroutine.
func (w *Worker) Wake() {
if w.wake == nil {
return
}
select {
case w.wake <- struct{}{}:
default:
}
}
@@ -93,6 +109,7 @@ func (w *Worker) Run(ctx context.Context) {
case <-ctx.Done():
return
case <-ticker.C:
case <-w.wake:
}
}
}
@@ -185,7 +202,12 @@ func (w *Worker) generateEdit(ctx context.Context, photoID string) {
w.failEdit(ctx, photoID, "fetch original: "+err.Error())
return
}
thumb, medium, preview, full, err := buildEditedVariants(data, params)
edited, err := decodeAndAdjust(data, params)
if err != nil {
w.failEdit(ctx, photoID, "decode original: "+err.Error())
return
}
thumb, medium, preview, err := encodeEditedVariants(edited)
if err != nil {
w.failEdit(ctx, photoID, "build edited variants: "+err.Error())
return
@@ -205,7 +227,10 @@ func (w *Worker) generateEdit(ctx context.Context, photoID string) {
w.failEdit(ctx, photoID, "store edit preview: "+err.Error())
return
}
if len(full) > 0 {
// The visible variants are ready: notify right away, so the grid and the
// viewer show the edit while the full-size version is still encoding.
w.notify(ctx, photoID)
if full, err := encodeEditedFull(edited); err == nil && len(full) > 0 {
if err := w.createVariant(ctx, owner, RoleEdit, full); err != nil {
w.failEdit(ctx, photoID, "store edit: "+err.Error())
return