Skip to content

Commit

Permalink
Adding wishlisted owned vet
Browse files Browse the repository at this point in the history
  • Loading branch information
boggydigital committed Oct 16, 2023
1 parent 54768d7 commit 546b762
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 69 deletions.
77 changes: 8 additions & 69 deletions cli/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (
"github.com/arelate/vangogh_local_data"
"github.com/boggydigital/nod"
"net/url"
"os"
"strconv"
"time"
)

const (
Expand All @@ -23,6 +20,7 @@ const (
VetStaleDehydrations = "stale-dehydrations"
VetOldLogs = "old-logs"
VetOldBackups = "old-backups"
VetWishlistedOwned = "wishlisted-owned"
)

type vetOptions struct {
Expand All @@ -37,6 +35,7 @@ type vetOptions struct {
missingChecksums bool
oldLogs bool
oldBackups bool
wishlistedOwned bool
}

func initVetOptions(u *url.URL) *vetOptions {
Expand All @@ -53,6 +52,7 @@ func initVetOptions(u *url.URL) *vetOptions {
staleDehydrations: vangogh_local_data.FlagFromUrl(u, VetStaleDehydrations),
oldLogs: vangogh_local_data.FlagFromUrl(u, VetOldLogs),
oldBackups: vangogh_local_data.FlagFromUrl(u, VetOldBackups),
wishlistedOwned: vangogh_local_data.FlagFromUrl(u, VetWishlistedOwned),
}

if vangogh_local_data.FlagFromUrl(u, "all") {
Expand All @@ -67,6 +67,7 @@ func initVetOptions(u *url.URL) *vetOptions {
vo.staleDehydrations = !vangogh_local_data.FlagFromUrl(u, NegOpt(VetStaleDehydrations))
vo.oldLogs = !vangogh_local_data.FlagFromUrl(u, NegOpt(VetOldLogs))
vo.oldBackups = !vangogh_local_data.FlagFromUrl(u, NegOpt(VetOldBackups))
vo.wishlistedOwned = !vangogh_local_data.FlagFromUrl(u, NegOpt(VetWishlistedOwned))
}

return vo
Expand Down Expand Up @@ -165,75 +166,13 @@ func Vet(
}
}

//products with values different from redux

return nil
}

// StaleDehydrations needs to be in cli to avoid import cycle
func StaleDehydrations(fix bool) error {

if err := staleDehydrationsImageType(
vangogh_local_data.ImageProperty,
vangogh_local_data.DehydratedImageModifiedProperty, fix); err != nil {
return err
}

if err := staleDehydrationsImageType(
vangogh_local_data.VerticalImageProperty,
vangogh_local_data.DehydratedVerticalImageModifiedProperty, fix); err != nil {
return err
}

return nil
}

func staleDehydrationsImageType(imageProperty, dimProperty string, fix bool) error {

sdia := nod.NewProgress("checking stale dehydrations for %s...", imageProperty)
defer sdia.End()

rxa, err := vangogh_local_data.ConnectReduxAssets(imageProperty, dimProperty)
if err != nil {
return err
}

staleIds := make(map[string]bool)

ids := rxa.Keys(imageProperty)
sdia.TotalInt(len(ids))

for _, id := range ids {
if imageId, ok := rxa.GetFirstVal(imageProperty, id); ok {
imagePath, err := vangogh_local_data.AbsLocalImagePath(imageId)
if err != nil {
return sdia.EndWithError(err)
}
if stat, err := os.Stat(imagePath); err == nil {
if dimStr, ok := rxa.GetFirstVal(dimProperty, id); ok {
if dim, err := strconv.ParseInt(dimStr, 10, 64); err == nil {
dimTime := time.Unix(dim, 0)
imt := stat.ModTime()
if imt.After(dimTime) {
staleIds[id] = true
}
}
}
}
if vetOpts.wishlistedOwned {
if err := WishlistedOwned(fix); err != nil {
return sda.EndWithError(err)
}
sdia.Increment()
}

if len(staleIds) == 0 {
sdia.EndWithResult("all good")
} else {
sdia.EndWithResult("found %d stale dehydrations", len(staleIds))
if fix {
imageType := vangogh_local_data.ImageTypeFromProperty(imageProperty)
return Dehydrate(staleIds, []vangogh_local_data.ImageType{imageType}, false)
}

}
//products with values different from redux

return nil
}
77 changes: 77 additions & 0 deletions cli/vet_stale_dehydrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package cli

import (
"github.com/arelate/vangogh_local_data"
"github.com/boggydigital/nod"
"os"
"strconv"
"time"
)

// StaleDehydrations needs to be in cli to avoid import cycle
func StaleDehydrations(fix bool) error {

if err := staleDehydrationsImageType(
vangogh_local_data.ImageProperty,
vangogh_local_data.DehydratedImageModifiedProperty, fix); err != nil {
return err
}

if err := staleDehydrationsImageType(
vangogh_local_data.VerticalImageProperty,
vangogh_local_data.DehydratedVerticalImageModifiedProperty, fix); err != nil {
return err
}

return nil
}

func staleDehydrationsImageType(imageProperty, dimProperty string, fix bool) error {

sdia := nod.NewProgress("checking stale dehydrations for %s...", imageProperty)
defer sdia.End()

rxa, err := vangogh_local_data.ConnectReduxAssets(imageProperty, dimProperty)
if err != nil {
return err
}

staleIds := make(map[string]bool)

ids := rxa.Keys(imageProperty)
sdia.TotalInt(len(ids))

for _, id := range ids {
if imageId, ok := rxa.GetFirstVal(imageProperty, id); ok {
imagePath, err := vangogh_local_data.AbsLocalImagePath(imageId)
if err != nil {
return sdia.EndWithError(err)
}
if stat, err := os.Stat(imagePath); err == nil {
if dimStr, ok := rxa.GetFirstVal(dimProperty, id); ok {
if dim, err := strconv.ParseInt(dimStr, 10, 64); err == nil {
dimTime := time.Unix(dim, 0)
imt := stat.ModTime()
if imt.After(dimTime) {
staleIds[id] = true
}
}
}
}
}
sdia.Increment()
}

if len(staleIds) == 0 {
sdia.EndWithResult("all good")
} else {
sdia.EndWithResult("found %d stale dehydrations", len(staleIds))
if fix {
imageType := vangogh_local_data.ImageTypeFromProperty(imageProperty)
return Dehydrate(staleIds, []vangogh_local_data.ImageType{imageType}, false)
}

}

return nil
}
51 changes: 51 additions & 0 deletions cli/vet_wishlisted_owned.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cli

import (
"github.com/arelate/vangogh_local_data"
"github.com/boggydigital/nod"
)

func WishlistedOwned(fix bool) error {

woa := nod.Begin("checking wishlisted owned products...")
defer woa.End()

rxa, err := vangogh_local_data.ConnectReduxAssets(
vangogh_local_data.WishlistedProperty,
vangogh_local_data.OwnedProperty)

if err != nil {
return woa.EndWithError(err)
}

woid := make([]string, 0)

for _, id := range rxa.Keys(vangogh_local_data.WishlistedProperty) {
// only check actually wishlisted products, not just any wishlisted state
if rxa.HasVal(vangogh_local_data.WishlistedProperty, id, vangogh_local_data.FalseValue) {
continue
}
if rxa.HasVal(vangogh_local_data.OwnedProperty, id, vangogh_local_data.TrueValue) {
woid = append(woid, id)
}
}

if len(woid) > 0 {
woa.EndWithResult("found %d product(s)", len(woid))

if fix {
rwoa := nod.Begin(" removing products from wishlist...")

if err := Wishlist(nil, woid); err != nil {
return rwoa.EndWithError(err)
}

rwoa.EndWithResult("done")
}

} else {
woa.EndWithResult("all good")
}

return nil
}
1 change: 1 addition & 0 deletions clo_delegates/clo_values_delegates.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ func vetOptions() []string {
cli.VetStaleDehydrations,
cli.VetOldLogs,
cli.VetOldBackups,
cli.VetWishlistedOwned,
})
}

0 comments on commit 546b762

Please sign in to comment.