Skip to content

Commit

Permalink
Revert "サムネイル情報を一度で取得"
Browse files Browse the repository at this point in the history
This reverts commit 59201bd.
  • Loading branch information
azbcww committed Nov 27, 2023
1 parent d65701a commit 93faae0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 58 deletions.
36 changes: 0 additions & 36 deletions repository/gorm/stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,39 +343,3 @@ func (r *stampRepository) GetStampStats(stampID uuid.UUID) (*repository.StampSta
}
return &stats, nil
}

func (r *stampRepository) StampThumbnailExists(stamps []*model.Stamp) (stampsWithThumb []repository.StampWithThumbnail, err error) {
IDs := make([]uuid.UUID, len(stamps))

for i, s := range stamps {
IDs[i] = s.FileID
}
ts := []uuid.UUID{}
if err = r.db.
Table("files_thumbnails ft").
Select("file_id").
Where("file_id IN (?)", IDs).
Find(&ts).
Error; err != nil {
return stampsWithThumb, err
}
tm := make(map[uuid.UUID]struct{}, len(ts))
for _, v := range ts {
tm[v] = struct{}{}
}

for _, s := range(stamps) {
_, ok := tm[s.FileID]
stampsWithThumb = append(stampsWithThumb, repository.StampWithThumbnail{
ID: s.ID,
Name: s.Name,
CreatorID: s.CreatorID,
FileID: s.FileID,
IsUnicode: s.IsUnicode,
CreatedAt: s.CreatedAt,
UpdatedAt: s.UpdatedAt,
HasThumbnail: ok,
})
}
return
}
16 changes: 0 additions & 16 deletions repository/stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ type StampStats struct {
TotalCount int64 `json:"totalCount"`
}

type StampWithThumbnail struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
CreatorID uuid.UUID `json:"creatorId"`
FileID uuid.UUID `json:"fileId"`
IsUnicode bool `json:"isUnicode"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
HasThumbnail bool `json:"hasThumbnail"`
}

// StampType スタンプの種類
type StampType string

Expand Down Expand Up @@ -125,9 +114,4 @@ type StampRepository interface {
// stampIDにNILを渡した場合、(nil, ErrNilID)を返します。
// DBによるエラーを返すことがあります。
GetStampStats(stampID uuid.UUID) (*StampStats, error)
// StampThumbnailExists スタンプ情報にサムネイルの有無を示すbool値を付加した構造体の配列を返します
//
// 成功した場合、当該配列とnilを返します
// DBによるエラーを返すことがあります。
StampThumbnailExists(stamps []*model.Stamp) (stampsWithThumb []StampWithThumbnail, err error)
}
7 changes: 1 addition & 6 deletions router/v3/stamps.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ func (h *Handlers) GetStamps(c echo.Context) error {
return herror.InternalServerError(err)
}

stampsWithThumb, err := h.Repo.StampThumbnailExists(stamps)
if err != nil {
return herror.InternalServerError(err)
}

return extension.ServeJSONWithETag(c, stampsWithThumb)
return extension.ServeJSONWithETag(c, stamps)
}

// CreateStamp POST /stamps
Expand Down

0 comments on commit 93faae0

Please sign in to comment.