Skip to content

Commit

Permalink
refactor: rename a field
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Jan 21, 2025
1 parent 8eb89a0 commit feb29c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/vacuum/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Controller struct {
stdout io.Writer
Param *config.Param
fs afero.Fs
d *DB
db *DB
}

// New initializes a Controller with the given context, parameters, and dependencies.
Expand All @@ -22,7 +22,7 @@ func New(ctx context.Context, param *config.Param, fs afero.Fs) *Controller {
stdout: os.Stdout,
Param: param,
fs: fs,
d: NewDB(ctx, param, fs),
db: NewDB(ctx, param, fs),
}
return vc
}
2 changes: 1 addition & 1 deletion pkg/controller/vacuum/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (vc *Controller) ListPackages(ctx context.Context, logE *logrus.Entry, expi

// handleListPackages retrieves a list of packages and displays them using a fuzzy search.
func (vc *Controller) handleListPackages(ctx context.Context, logE *logrus.Entry, args ...string) error {
pkgs, err := vc.d.List(ctx, logE)
pkgs, err := vc.db.List(ctx, logE)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/vacuum/vacuum.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func (vc *Controller) Close(logE *logrus.Entry) error {
return nil
}
logE.Debug("closing vacuum controller")
if vc.d.storeQueue != nil {
vc.d.storeQueue.close()
if vc.db.storeQueue != nil {
vc.db.storeQueue.close()
}
return vc.d.Close()
return vc.db.Close()
}

func (vc *Controller) TestKeepDBOpen() error {
return vc.d.TestKeepDBOpen()
return vc.db.TestKeepDBOpen()
}

// StorePackage stores the given package if vacuum is enabled.
Expand Down Expand Up @@ -80,7 +80,7 @@ func (vc *Controller) IsVacuumEnabled(logE *logrus.Entry) bool {
// GetPackageLastUsed retrieves the last used time of a package. for testing purposes.
func (vc *Controller) GetPackageLastUsed(ctx context.Context, logE *logrus.Entry, pkgPath string) *time.Time {
var lastUsedTime time.Time
pkgEntry, _ := vc.d.Get(ctx, logE, pkgPath)
pkgEntry, _ := vc.db.Get(ctx, logE, pkgPath)
if pkgEntry != nil {
lastUsedTime = pkgEntry.LastUsageTime
}
Expand All @@ -89,7 +89,7 @@ func (vc *Controller) GetPackageLastUsed(ctx context.Context, logE *logrus.Entry

// SetTimeStampPackage permit define a Timestamp for a package Manually. for testing purposes.
func (vc *Controller) SetTimestampPackage(ctx context.Context, logE *logrus.Entry, pkg *config.Package, pkgPath string, datetime time.Time) error {
return vc.d.Store(ctx, logE, vc.getVacuumPackage(pkg, pkgPath), datetime)
return vc.db.Store(ctx, logE, vc.getVacuumPackage(pkg, pkgPath), datetime)
}

// getVacuumPackage converts a config
Expand All @@ -106,7 +106,7 @@ func (vc *Controller) handleAsyncStorePackage(logE *logrus.Entry, vacuumPkg *Pac
if vacuumPkg == nil {
return errors.New("vacuumPkg is nil")
}
vc.d.storeQueue.enqueue(logE, vacuumPkg)
vc.db.storeQueue.enqueue(logE, vacuumPkg)
return nil
}

Expand All @@ -127,7 +127,7 @@ func (vc *Controller) isPackageExpired(pkg *PackageVacuumEntry) bool {

// listExpiredPackages lists all packages that have expired based on the vacuum configuration.
func (vc *Controller) listExpiredPackages(ctx context.Context, logE *logrus.Entry) ([]*PackageVacuumEntry, error) {
pkgs, err := vc.d.List(ctx, logE)
pkgs, err := vc.db.List(ctx, logE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (vc *Controller) vacuumExpiredPackages(ctx context.Context, logE *logrus.En
}

if len(successfulRemovals) > 0 {
if err := vc.d.RemovePackages(ctx, logE, successfulRemovals); err != nil {
if err := vc.db.RemovePackages(ctx, logE, successfulRemovals); err != nil {
return fmt.Errorf("remove packages from database: %w", err)
}
}
Expand Down

0 comments on commit feb29c2

Please sign in to comment.