Skip to content

Commit

Permalink
satellite/metabase: adjust other Get queries
Browse files Browse the repository at this point in the history
Change-Id: I6445328ad03e0b8cbcbad33b76d9ef30c41a804e
  • Loading branch information
egonelbre authored and Storj Robot committed Oct 23, 2023
1 parent ff9013b commit 0c7ad88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
41 changes: 13 additions & 28 deletions satellite/metabase/get.go
Expand Up @@ -204,9 +204,7 @@ func (db *DB) GetSegmentByPosition(ctx context.Context, opts GetSegmentByPositio
inline_data, remote_alias_pieces,
placement
FROM segments
WHERE
stream_id = $1 AND
position = $2
WHERE (stream_id, position) = ($1, $2)
`, opts.StreamID, opts.Position.Encode()).
Scan(
&segment.CreatedAt, &segment.ExpiresAt, &segment.RepairedAt,
Expand Down Expand Up @@ -263,13 +261,14 @@ func (db *DB) GetLatestObjectLastSegment(ctx context.Context, opts GetLatestObje
placement
FROM segments
WHERE
stream_id IN (SELECT stream_id FROM objects WHERE
project_id = $1 AND
bucket_name = $2 AND
object_key = $3 AND
status = `+statusCommittedUnversioned+`
ORDER BY version DESC
LIMIT 1
stream_id IN (
SELECT stream_id
FROM objects
WHERE
(project_id, bucket_name, object_key) = ($1, $2, $3) AND
status <> `+statusPending+`
ORDER BY version DESC
LIMIT 1
)
ORDER BY position DESC
LIMIT 1
Expand Down Expand Up @@ -319,31 +318,17 @@ func (db *DB) BucketEmpty(ctx context.Context, opts BucketEmpty) (empty bool, er
return false, ErrInvalidRequest.New("BucketName missing")
}

var value int
var value bool
err = db.db.QueryRowContext(ctx, `
SELECT
1
FROM objects
WHERE
project_id = $1 AND
bucket_name = $2
UNION ALL
SELECT
1
FROM pending_objects
WHERE
project_id = $1 AND
bucket_name = $2
LIMIT 1
(SELECT EXISTS (SELECT 1 FROM objects WHERE (project_id, bucket_name) = ($1, $2))) OR
(SELECT EXISTS (SELECT 1 FROM pending_objects WHERE (project_id, bucket_name) = ($1, $2)))
`, opts.ProjectID, []byte(opts.BucketName)).Scan(&value)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return true, nil
}
return false, Error.New("unable to query objects: %w", err)
}

return false, nil
return !value, nil
}

// TestingAllCommittedObjects gets all objects from bucket.
Expand Down
4 changes: 4 additions & 0 deletions satellite/metabase/get_test.go
Expand Up @@ -1605,6 +1605,10 @@ func TestGetLatestObjectLastSegment(t *testing.T) {
},
}.Check(ctx, t, db)
})

// TODO(ver): add test for committed versioned
// TODO(ver): add test for delete marker versioned
// TODO(ver): add test for delete marker unversioned
})
}

Expand Down

0 comments on commit 0c7ad88

Please sign in to comment.