Skip to content

Commit

Permalink
fix(total-size): calculation not accounting for database commas in li…
Browse files Browse the repository at this point in the history
…sts (#296)
  • Loading branch information
KellyMerrick authored Jun 14, 2023
1 parent 3317520 commit b1b57c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ func (r *Repo) Validate() error {
}

// verify the Favorites field is within the database constraints
if total > constants.TopicsMaxSize {
// len is to factor in number of comma separators included in the database field,
// removing 1 due to the last item not having an appended comma
if (total + len(r.Topics) - 1) > constants.TopicsMaxSize {
return ErrExceededTopicsLimit
}

Expand Down
4 changes: 3 additions & 1 deletion database/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ func (u *User) Validate() error {
}

// verify the Favorites field is within the database constraints
if total > constants.FavoritesMaxSize {
// len is to factor in number of comma separators included in the database field,
// removing 1 due to the last item not having an appended comma
if (total + len(u.Favorites) - 1) > constants.FavoritesMaxSize {
return ErrExceededFavoritesLimit
}

Expand Down
4 changes: 3 additions & 1 deletion database/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ func (w *Worker) Validate() error {
}

// verify the RunningBuildIds field is within the database constraints
if total > constants.RunningBuildIDsMaxSize {
// len is to factor in number of comma separators included in the database field,
// removing 1 due to the last item not having an appended comma
if (total + len(w.RunningBuildIDs) - 1) > constants.RunningBuildIDsMaxSize {
return ErrExceededRunningBuildIDsLimit
}

Expand Down

0 comments on commit b1b57c0

Please sign in to comment.