Revert "modules: Throttle the "downloading modules …" log entries"

This reverts commit 66904097e0.
This commit is contained in:
Bjørn Erik Pedersen 2023-10-29 10:57:27 +01:00
parent eb5fd3127f
commit 28d844642a
No known key found for this signature in database
2 changed files with 18 additions and 28 deletions

View file

@ -18,7 +18,6 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -47,6 +46,8 @@ import (
"github.com/gohugoio/hugo/common/hugio" "github.com/gohugoio/hugo/common/hugio"
"errors"
"github.com/spf13/afero" "github.com/spf13/afero"
) )
@ -104,25 +105,10 @@ func NewClient(cfg ClientConfig) *Client {
noVendor, _ = hglob.GetGlob(hglob.NormalizePath(cfg.ModuleConfig.NoVendor)) noVendor, _ = hglob.GetGlob(hglob.NormalizePath(cfg.ModuleConfig.NoVendor))
} }
var throttleSince time.Time
throttle := func(f func()) {
if throttleSince.IsZero() {
throttleSince = time.Now()
f()
return
}
if time.Since(throttleSince) < 6*time.Second {
return
}
throttleSince = time.Now()
f()
}
return &Client{ return &Client{
fs: fs, fs: fs,
ccfg: cfg, ccfg: cfg,
logger: logger, logger: logger,
throttle: throttle,
noVendor: noVendor, noVendor: noVendor,
moduleConfig: mcfg, moduleConfig: mcfg,
environ: env, environ: env,
@ -132,9 +118,8 @@ func NewClient(cfg ClientConfig) *Client {
// Client contains most of the API provided by this package. // Client contains most of the API provided by this package.
type Client struct { type Client struct {
fs afero.Fs fs afero.Fs
logger loggers.Logger logger loggers.Logger
throttle func(f func())
noVendor glob.Glob noVendor glob.Glob
@ -214,7 +199,7 @@ func (c *Client) Vendor() error {
if err := c.rmVendorDir(vendorDir); err != nil { if err := c.rmVendorDir(vendorDir); err != nil {
return err return err
} }
if err := c.fs.MkdirAll(vendorDir, 0o755); err != nil { if err := c.fs.MkdirAll(vendorDir, 0755); err != nil {
return err return err
} }
@ -275,7 +260,7 @@ func (c *Client) Vendor() error {
} else { } else {
targetDir := filepath.Dir(targetFilename) targetDir := filepath.Dir(targetFilename)
if err := c.fs.MkdirAll(targetDir, 0o755); err != nil { if err := c.fs.MkdirAll(targetDir, 0755); err != nil {
return fmt.Errorf("failed to make target dir: %w", err) return fmt.Errorf("failed to make target dir: %w", err)
} }
@ -318,7 +303,7 @@ func (c *Client) Vendor() error {
} }
if modulesContent.Len() > 0 { if modulesContent.Len() > 0 {
if err := afero.WriteFile(c.fs, filepath.Join(vendorDir, vendorModulesFilename), modulesContent.Bytes(), 0o666); err != nil { if err := afero.WriteFile(c.fs, filepath.Join(vendorDir, vendorModulesFilename), modulesContent.Bytes(), 0666); err != nil {
return err return err
} }
} }
@ -573,7 +558,7 @@ func (c *Client) rewriteGoMod(name string, isGoMod map[string]bool) error {
return err return err
} }
if data != nil { if data != nil {
if err := afero.WriteFile(c.fs, filepath.Join(c.ccfg.WorkingDir, name), data, 0o666); err != nil { if err := afero.WriteFile(c.fs, filepath.Join(c.ccfg.WorkingDir, name), data, 0666); err != nil {
return err return err
} }
} }
@ -651,8 +636,7 @@ func (c *Client) rmVendorDir(vendorDir string) error {
func (c *Client) runGo( func (c *Client) runGo(
ctx context.Context, ctx context.Context,
stdout io.Writer, stdout io.Writer,
args ...string, args ...string) error {
) error {
if c.goBinaryStatus != 0 { if c.goBinaryStatus != 0 {
return nil return nil
} }

View file

@ -15,7 +15,6 @@ package modules
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -23,6 +22,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/bep/debounce"
"github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/common/loggers"
@ -37,6 +37,8 @@ import (
"github.com/rogpeppe/go-internal/module" "github.com/rogpeppe/go-internal/module"
"errors"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/spf13/afero" "github.com/spf13/afero"
) )
@ -122,6 +124,7 @@ func (m ModulesConfig) HasConfigFile() bool {
if len(mod.ConfigFilenames()) > 0 { if len(mod.ConfigFilenames()) > 0 {
return true return true
} }
} }
return false return false
} }
@ -217,6 +220,7 @@ func (c *collector) getVendoredDir(path string) (vendoredModule, bool) {
} }
func (c *collector) add(owner *moduleAdapter, moduleImport Import) (*moduleAdapter, error) { func (c *collector) add(owner *moduleAdapter, moduleImport Import) (*moduleAdapter, error) {
var ( var (
mod *goModule mod *goModule
moduleDir string moduleDir string
@ -505,10 +509,11 @@ LOOP:
func (c *collector) collect() { func (c *collector) collect() {
defer c.logger.PrintTimerIfDelayed(time.Now(), "hugo: collected modules") defer c.logger.PrintTimerIfDelayed(time.Now(), "hugo: collected modules")
d := debounce.New(2 * time.Second)
c.throttle(func() { d(func() {
c.logger.Println("hugo: downloading modules …") c.logger.Println("hugo: downloading modules …")
}) })
defer d(func() {})
if err := c.initModules(); err != nil { if err := c.initModules(); err != nil {
c.err = err c.err = err
@ -664,6 +669,7 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
} else { } else {
continue continue
} }
} }
// Verify that target points to one of the predefined component dirs // Verify that target points to one of the predefined component dirs