Skip to content

Commit

Permalink
Merge pull request #192 from kitagry/fix-list-projects
Browse files Browse the repository at this point in the history
refactor: speed up ListProjects
  • Loading branch information
kitagry authored Dec 15, 2024
2 parents a9518fa + 5846de2 commit 560f734
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion langserver/internal/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *client) GetDefaultProject() string {
}

func (c *client) ListProjects(ctx context.Context) ([]*cloudresourcemanager.Project, error) {
caller := c.cloudresourcemanagerService.Projects.List().Context(ctx)
caller := c.cloudresourcemanagerService.Projects.List().PageSize(1000).Context(ctx)

list, err := caller.Do()
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions langserver/internal/bigquery/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ func (c *cache) callListProjects(ctx context.Context) ([]*cloudresourcemanager.P
}

if len(result) > 0 {
err := c.db.InsertProjects(ctx, result)
if err != nil {
// TODO
fmt.Fprintf(os.Stderr, "failed to insert projects: %v\n", err)
insertSize := 1000
for i := 0; i < len(result); i += insertSize {
insertItems := result[i:min(len(result), i+insertSize)]
err := c.db.InsertProjects(ctx, insertItems)
if err != nil {
// TODO
fmt.Fprintf(os.Stderr, "failed to insert projects: %v\n", err)
}
}
}
return result, nil
Expand Down

0 comments on commit 560f734

Please sign in to comment.