HasSheets checks if all sheets exist by SHA256 hashes.
(ctx context.Context, sha256Hexes ...string)
| 144 | |
| 145 | // HasSheets checks if all sheets exist by SHA256 hashes. |
| 146 | func (s *Store) HasSheets(ctx context.Context, sha256Hexes ...string) (bool, error) { |
| 147 | if len(sha256Hexes) == 0 { |
| 148 | return true, nil |
| 149 | } |
| 150 | |
| 151 | // Remove duplicates |
| 152 | sha256Hexes = common.Uniq(sha256Hexes) |
| 153 | |
| 154 | q := qb.Q().Space(` |
| 155 | SELECT COUNT(*) |
| 156 | FROM sheet_blob |
| 157 | WHERE sha256 IN (SELECT decode(unnest(CAST(? AS TEXT[])), 'hex'))`, |
| 158 | sha256Hexes) |
| 159 | |
| 160 | query, args, err := q.ToSQL() |
| 161 | if err != nil { |
| 162 | return false, errors.Wrapf(err, "failed to build sql") |
| 163 | } |
| 164 | |
| 165 | var count int |
| 166 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(&count); err != nil { |
| 167 | return false, err |
| 168 | } |
| 169 | |
| 170 | return count == len(sha256Hexes), nil |
| 171 | } |