Skip to content

Commit

Permalink
Do not return value in console storage listing
Browse files Browse the repository at this point in the history
The console storage list view has no use for the value, which
for large stored values on low hardware deployments could cause
an OOM.
  • Loading branch information
sesposito committed May 6, 2024
1 parent b4d27d1 commit c0ee07a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/console_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
var cursor *consoleStorageCursor
if in.Cursor != "" {
// Pagination not allowed when filtering only by user ID. Don't process the cursor further.
if in.Collection == "" && in.Key == "" {
if in.Collection == "" && in.Key == "" && userID != nil {
return nil, status.Error(codes.InvalidArgument, "Cursor not allowed when filter only contains user ID.")
}
// Pagination not allowed when filtering by collection, key, and user ID all at once. Don't process the cursor further.
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
switch {
case in.Collection == "" && in.Key == "" && userID == nil:
// No filter. Querying and paginating on primary key (collection, read, key, user_id).
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage"
if cursor != nil {
params = append(params, cursor.Collection, cursor.Read, cursor.Key, cursor.UserID)
query += " WHERE (collection, read, key, user_id) > ($1, $2, $3, $4)"
Expand All @@ -212,11 +212,11 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
// Filtering by user ID only returns all results, no pagination or limit.
limit = 0
params = []interface{}{*userID}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE user_id = $1"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE user_id = $1"
case in.Collection != "" && in.Key == "" && userID == nil:
// Collection only. Querying and paginating on primary key (collection, read, key, user_id).
params = []interface{}{in.Collection}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE collection = $1"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1"
if cursor != nil {
params = append(params, cursor.Read, cursor.Key, cursor.UserID)
query += " AND (collection, read, key, user_id) > ($1, $2, $3, $4)"
Expand All @@ -226,7 +226,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
case in.Collection != "" && in.Key != "" && userID == nil && isPrefixSearch(in.Key):
// Collection and key%. Querying and paginating on unique index (collection, key, user_id).
params = []interface{}{in.Collection, in.Key}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key LIKE $2"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key LIKE $2"
if cursor != nil {
params = append(params, cursor.Key, cursor.UserID)
query += " AND (collection, key, user_id) > ($1, $3, $4)"
Expand All @@ -236,7 +236,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
case in.Collection != "" && in.Key != "" && userID == nil:
// Collection and key. Querying and paginating on unique index (collection, key, user_id).
params = []interface{}{in.Collection, in.Key}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key = $2"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key = $2"
if cursor != nil {
params = append(params, cursor.UserID)
query += " AND (collection, key, user_id) > ($1, $2, $3)"
Expand All @@ -246,7 +246,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
case in.Collection != "" && in.Key == "" && userID != nil:
// Collection and user ID. Querying and paginating on index (collection, user_id, read, key).
params = []interface{}{in.Collection, *userID}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND user_id = $2"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND user_id = $2"
if cursor != nil {
params = append(params, cursor.Read, cursor.Key)
query += " AND (collection, user_id, read, key) > ($1, $2, $3, $4)"
Expand All @@ -256,7 +256,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
case in.Collection != "" && in.Key != "" && userID != nil && isPrefixSearch(in.Key):
// Collection, key%, user ID. Querying and paginating on unique index (collection, key, user_id).
params = []interface{}{in.Collection, in.Key, *userID}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key LIKE $2 AND user_id = $3"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key LIKE $2 AND user_id = $3"
if cursor != nil {
params = append(params, cursor.Key)
query += " AND (collection, key, user_id) > ($1, $4, $3)"
Expand All @@ -267,7 +267,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
// Filtering by collection, key, user ID returns 0 or 1 results, no pagination or limit. Querying on unique index (collection, key, user_id).
limit = 0
params = []interface{}{in.Collection, in.Key, *userID}
query = "SELECT collection, key, user_id, value, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key = $2 AND user_id = $3"
query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1 AND key = $2 AND user_id = $3"
default:
return nil, status.Error(codes.InvalidArgument, "Requires a valid combination of filters.")
}
Expand Down Expand Up @@ -298,7 +298,7 @@ func (s *ConsoleServer) ListStorage(ctx context.Context, in *console.ListStorage
var createTime pgtype.Timestamptz
var updateTime pgtype.Timestamptz

if err := rows.Scan(&o.Collection, &o.Key, &o.UserId, &o.Value, &o.Version, &o.PermissionRead, &o.PermissionWrite, &createTime, &updateTime); err != nil {
if err := rows.Scan(&o.Collection, &o.Key, &o.UserId, &o.Version, &o.PermissionRead, &o.PermissionWrite, &createTime, &updateTime); err != nil {
_ = rows.Close()
s.logger.Error("Error scanning storage objects.", zap.Any("in", in), zap.Error(err))
return nil, status.Error(codes.Internal, "An error occurred while trying to list storage objects.")
Expand Down

0 comments on commit c0ee07a

Please sign in to comment.