Skip to content

Commit a509700

Browse files
retlehsclaude
andcommitted
Limit dev mode to seeded packages only and fix lint errors
Dev build was processing all ~46,500 packages in the DB (from prior SVN discovery), hitting macOS file descriptor limits. Now dev.go filters both the metadata fetch and build steps to only the ~27 seed config packages. Also fix unchecked errcheck warnings in handlers.go and server.go. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c44da48 commit a509700

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

cmd/wpcomposer/cmd/dev.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ func runDev(cmd *cobra.Command, args []string) error {
6767
return fmt.Errorf("discover: %w", err)
6868
}
6969

70-
// 4. Update all packages
70+
// 4. Update seeded packages only
71+
seeds, err := packages.LoadSeeds(application.Config.Discovery.SeedsFile)
72+
if err != nil {
73+
return fmt.Errorf("loading seeds: %w", err)
74+
}
75+
seedSlugs := append(seeds.PopularPlugins, seeds.PopularThemes...)
76+
7177
application.Logger.Info("dev: fetching package metadata")
7278
syncRun, err := packages.AllocateSyncRunID(ctx, application.DB)
7379
if err != nil {
@@ -76,6 +82,7 @@ func runDev(cmd *cobra.Command, args []string) error {
7682

7783
pkgs, err := packages.GetPackagesNeedingUpdate(ctx, application.DB, packages.UpdateQueryOpts{
7884
Type: "all",
85+
Names: seedSlugs,
7986
Force: true,
8087
})
8188
if err != nil {
@@ -127,10 +134,11 @@ func runDev(cmd *cobra.Command, args []string) error {
127134
application.Logger.Info("dev: building repository")
128135
output := filepath.Join("storage", "repository", "builds")
129136
result, err := repository.Build(ctx, application.DB, repository.BuildOpts{
130-
OutputDir: output,
131-
AppURL: application.Config.AppURL,
132-
Force: true,
133-
Logger: application.Logger,
137+
OutputDir: output,
138+
AppURL: application.Config.AppURL,
139+
Force: true,
140+
PackageNames: seedSlugs,
141+
Logger: application.Logger,
134142
})
135143
if err != nil {
136144
return fmt.Errorf("build: %w", err)

internal/http/handlers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func handleAdminLogStream(a *app.App) http.HandlerFunc {
361361
if opened, err := os.Open(logPath); err == nil {
362362
f = opened
363363
} else {
364-
fmt.Fprintf(w, "data: Waiting for %s ...\n\n", filepath.Base(logPath))
364+
_, _ = fmt.Fprintf(w, "data: Waiting for %s ...\n\n", filepath.Base(logPath))
365365
flusher.Flush()
366366
select {
367367
case <-ctx.Done():
@@ -370,12 +370,12 @@ func handleAdminLogStream(a *app.App) http.HandlerFunc {
370370
}
371371
}
372372
}
373-
defer f.Close()
373+
defer func() { _ = f.Close() }()
374374

375375
// Send initial batch: last 200 lines
376376
lines := tailFile(logPath, 200)
377377
for _, line := range lines {
378-
fmt.Fprintf(w, "data: %s\n\n", line)
378+
_, _ = fmt.Fprintf(w, "data: %s\n\n", line)
379379
}
380380
flusher.Flush()
381381

@@ -395,7 +395,7 @@ func handleAdminLogStream(a *app.App) http.HandlerFunc {
395395
}
396396
if info.Size() < offset {
397397
// File was truncated/rotated, reopen
398-
f.Close()
398+
_ = f.Close()
399399
f, err = os.Open(logPath)
400400
if err != nil {
401401
continue

internal/http/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func socketActivationListener() (net.Listener, error) {
8585
if f == nil {
8686
return nil, nil
8787
}
88-
defer f.Close()
88+
defer func() { _ = f.Close() }()
8989

9090
ln, err := net.FileListener(f)
9191
if err != nil {

internal/packages/package.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"encoding/json"
77
"fmt"
8+
"strings"
89
"time"
910

1011
"github.com/roots/wp-composer/internal/version"
@@ -248,6 +249,7 @@ func BatchUpsertPackages(ctx context.Context, db *sql.DB, pkgs []*Package) error
248249
type UpdateQueryOpts struct {
249250
Type string
250251
Name string
252+
Names []string // filter to these slugs only
251253
Force bool
252254
IncludeInactive bool
253255
Limit int
@@ -263,6 +265,15 @@ func GetPackagesNeedingUpdate(ctx context.Context, db *sql.DB, opts UpdateQueryO
263265
args = append(args, opts.Name)
264266
}
265267

268+
if len(opts.Names) > 0 {
269+
placeholders := make([]string, len(opts.Names))
270+
for i, n := range opts.Names {
271+
placeholders[i] = "?"
272+
args = append(args, n)
273+
}
274+
query += ` AND name IN (` + strings.Join(placeholders, ",") + `)`
275+
}
276+
266277
if opts.Type != "" && opts.Type != "all" {
267278
query += ` AND type = ?`
268279
args = append(args, opts.Type)

internal/repository/builder.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type BuildOpts struct {
1818
OutputDir string // base output dir (e.g. storage/repository/builds)
1919
AppURL string // absolute app URL for notify-batch
2020
Force bool
21-
PackageName string // optional: build single package
22-
PreviousBuildDir string // optional: previous build dir for incremental builds
21+
PackageName string // optional: build single package
22+
PackageNames []string // optional: build only these slugs
23+
PreviousBuildDir string // optional: previous build dir for incremental builds
2324
Logger *slog.Logger
2425
}
2526

@@ -97,6 +98,14 @@ func Build(ctx context.Context, db *sql.DB, opts BuildOpts) (*BuildResult, error
9798
query += ` AND (type || '/' || name) = ?`
9899
args = append(args, opts.PackageName)
99100
}
101+
if len(opts.PackageNames) > 0 {
102+
placeholders := make([]string, len(opts.PackageNames))
103+
for i, n := range opts.PackageNames {
104+
placeholders[i] = "?"
105+
args = append(args, n)
106+
}
107+
query += ` AND name IN (` + strings.Join(placeholders, ",") + `)`
108+
}
100109
query += ` ORDER BY type, name`
101110

102111
rows, err := db.QueryContext(ctx, query, args...)

0 commit comments

Comments
 (0)