update backend
This commit is contained in:
@ -14,8 +14,8 @@ import (
|
||||
"fashionapi/internal/repository"
|
||||
)
|
||||
|
||||
// MediaCleanupEnqueuer 是「清理七牛孤儿图」任务的入队入口;由 IngestService 实现,
|
||||
// 图集服务在删除图集时调用它,把同步的七牛删除改为异步队列,避免阻塞删除请求。
|
||||
// MediaCleanupEnqueuer 是「清理S4孤儿图」任务的入队入口;由 IngestService 实现,
|
||||
// 图集服务在删除图集时调用它,把同步的S4删除改为异步队列,避免阻塞删除请求。
|
||||
type MediaCleanupEnqueuer interface {
|
||||
EnqueueMediaCleanup(ctx context.Context, keys []string) error
|
||||
}
|
||||
@ -36,7 +36,7 @@ type ArticleService interface {
|
||||
SetCover(ctx context.Context, runwayID uint32, image string) error
|
||||
// SetDeleted 上下架:deleted=1 下架(对外不可见),0 上架。
|
||||
SetDeleted(ctx context.Context, id uint32, deleted uint8) error
|
||||
// PurgeGallery 彻底下架图集:级联软删图片 + 下架 + 异步入队清理七牛孤儿图。
|
||||
// PurgeGallery 彻底下架图集:级联软删图片 + 下架 + 异步入队清理S4孤儿图。
|
||||
PurgeGallery(ctx context.Context, id uint32) error
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ type articleService struct {
|
||||
media repository.MediaRepository
|
||||
img *imgurl.Composer
|
||||
deleter storage.Deleter
|
||||
cleaner MediaCleanupEnqueuer // 删除图集时异步清理七牛孤儿图的入队入口
|
||||
cleaner MediaCleanupEnqueuer // 删除图集时异步清理S4孤儿图的入队入口
|
||||
}
|
||||
|
||||
// NewArticleService 创建文章服务。
|
||||
@ -212,7 +212,7 @@ func (s *articleService) UpdateRunway(ctx context.Context, id uint32, fields map
|
||||
}
|
||||
|
||||
func (s *articleService) DeleteImage(ctx context.Context, imageID uint32) error {
|
||||
// 先取 key(删除前清理七牛孤儿用),再软删 DB 行,最后按引用计数决定是否真删七牛文件。
|
||||
// 先取 key(删除前清理S4孤儿用),再软删 DB 行,最后按引用计数决定是否真删S4文件。
|
||||
key, err := s.articles.GetRunwayImageKey(ctx, imageID)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -232,20 +232,20 @@ func (s *articleService) SetCover(ctx context.Context, runwayID uint32, image st
|
||||
|
||||
func (s *articleService) SetDeleted(ctx context.Context, id uint32, deleted uint8) error {
|
||||
if deleted == 1 {
|
||||
// 下架图集:软删图片 + 置下架 + 异步入队清理七牛孤儿图(见 PurgeGallery)。
|
||||
// 下架图集:软删图片 + 置下架 + 异步入队清理S4孤儿图(见 PurgeGallery)。
|
||||
return s.PurgeGallery(ctx, id)
|
||||
}
|
||||
// 上架(deleted=0)仅恢复图集行,不动图片/不清理(图片若已删不可恢复,属预期)。
|
||||
return s.articles.SetRunwayDeleted(ctx, id, 0)
|
||||
}
|
||||
|
||||
// PurgeGallery 下架图集并异步清理七牛孤儿图:
|
||||
// PurgeGallery 下架图集并异步清理S4孤儿图:
|
||||
// 1. 级联软删其全部图片(使其退出引用计数),拿到这些图片的 key;
|
||||
// 2. 把图集自身置为下架(对外不可见);
|
||||
// 3. 把这批 key 入队,由 worker 按引用计数判定是否为真孤儿再删七牛文件(异步、不阻塞本请求)。
|
||||
// 3. 把这批 key 入队,由 worker 按引用计数判定是否为真孤儿再删S4文件(异步、不阻塞本请求)。
|
||||
//
|
||||
// 仍被其他图集引用的 key 不会被误删(内容寻址共享 key 安全);入队失败仅告警,
|
||||
// 图集已下架、图片已软删,七牛文件留待后续手动清理或周期性兜底扫描。
|
||||
// 图集已下架、图片已软删,S4文件留待后续手动清理或周期性兜底扫描。
|
||||
func (s *articleService) PurgeGallery(ctx context.Context, id uint32) error {
|
||||
keys, err := s.articles.SoftDeleteRunwayImages(ctx, id)
|
||||
if err != nil {
|
||||
@ -256,7 +256,7 @@ func (s *articleService) PurgeGallery(ctx context.Context, id uint32) error {
|
||||
}
|
||||
if len(keys) > 0 && s.cleaner != nil {
|
||||
if err := s.cleaner.EnqueueMediaCleanup(ctx, keys); err != nil {
|
||||
log.Printf("[warn] 下架图集 %d 入队清理七牛失败(文件将暂留): %v", id, err)
|
||||
log.Printf("[warn] 下架图集 %d 入队清理S4失败(文件将暂留): %v", id, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user