feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Callers supply hosts already selected through the account/host access scope.
|
||||
// Batch reads avoid a separate usage query for every host in an account view.
|
||||
func (s *Store) FillProjectBandwidth(ctx context.Context, projects []Project) error {
|
||||
byID := make(map[uint64]int, len(projects))
|
||||
for i, p := range projects {
|
||||
byID[p.ID] = i
|
||||
}
|
||||
for start := 0; start < len(projects); start += 500 {
|
||||
end := min(start+500, len(projects))
|
||||
args := make([]any, 0, end-start)
|
||||
for _, p := range projects[start:end] {
|
||||
args = append(args, p.ID)
|
||||
}
|
||||
rows, err := s.db.QueryContext(ctx, "SELECT project_id,bandwidth_bytes FROM project_quota_usage WHERE project_id IN ("+strings.TrimSuffix(strings.Repeat("?,", len(args)), ",")+")", args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for rows.Next() {
|
||||
var id, used uint64
|
||||
if err = rows.Scan(&id, &used); err != nil {
|
||||
rows.Close()
|
||||
return err
|
||||
}
|
||||
if i, ok := byID[id]; ok {
|
||||
projects[i].BandwidthBytes = used
|
||||
}
|
||||
}
|
||||
err = rows.Err()
|
||||
rows.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user