add fix sizes command

This commit is contained in:
2024-02-11 15:56:39 +03:00
parent 8dad392451
commit 1460732ba2

View File

@ -375,10 +375,19 @@ func newViewItemsCmd() *cli.Command {
newViewItemsCountCmd(),
newViewItemsUniqueParams(),
newViewItemsParamsKnownValues(),
newViewItemsFixSizesCmd(),
},
}
}
func newViewItemsFixSizesCmd() *cli.Command {
return &cli.Command{
Name: "fix-sizes",
Usage: "Iterates over params and sets sizes from parameters",
Action: decorateAction(viewItemsFixSizesAction),
}
}
func newViewItemsUniqueParams() *cli.Command {
return &cli.Command{
Name: "unique-params",
@ -1109,6 +1118,37 @@ func parseEwayListAction(ctx context.Context, cmd *cli.Command) error {
return nil
}
func viewItemsFixSizesAction(ctx context.Context, cmd *cli.Command) error {
repository, err := components.GetRepository()
if err != nil {
return fmt.Errorf("getting repository: %w", err)
}
dimensionDispatcher := makeDefaultDimensionDispatcher()
toUpdate := make([]entity.GoodsItem, 0, 20_000)
bus := getItemsIter(ctx, repository.GoodsItem())
for bus.Next() {
item := bus.Get()
for key, value := range item.Parameters {
dimensionDispatcher.dispatch(ctx, value, key, &item.Sizes)
}
toUpdate = append(toUpdate, item)
}
if bus.Err() != nil {
return fmt.Errorf("iterating: %w", bus.Err())
}
_, err = repository.GoodsItem().UpsertMany(ctx, toUpdate...)
if err != nil {
return fmt.Errorf("updating items: %w", err)
}
return nil
}
func parseEwayDumpAction(ctx context.Context, cmd *cli.Command) error {
client, err := components.GetEwayClient()
if err != nil {