From 2a2a6b1f728715132920eb9ba93b0fd50b4ce66e Mon Sep 17 00:00:00 2001 From: Florian Baumann Date: Thu, 20 Oct 2022 14:48:24 +0200 Subject: [PATCH] Fix set insertion problem a lot easier --- src/serra/update.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/serra/update.go b/src/serra/update.go index 29420d0..c008c4a 100644 --- a/src/serra/update.go +++ b/src/serra/update.go @@ -33,7 +33,12 @@ var updateCmd = &cobra.Command{ sets, _ := fetch_sets() for _, set := range sets.Data { + + // When downloading new sets, PriceList needs to be initialized + // This query silently fails if set was already downloaded. Not nice but ok for now. + set.SerraPrices = []PriceEntry{} setscoll.storage_add_set(&set) + cards, _ := coll.storage_find(bson.D{{"set", set.Code}}, bson.D{{"_id", 1}}) // if no cards in collection for this set, skip it @@ -41,17 +46,6 @@ var updateCmd = &cobra.Command{ continue } - // Workaround for: - // "The field 'serra_prices' must be an array but is of type null in document" - // I dont know why I need to initialize this array alement as an empty array, but $push does - // not work on null fields. - if len(set.SerraPrices) == 0 { - set_init := bson.M{ - "$set": bson.M{"serra_prices": bson.A{}}, - } - setscoll.storage_update(bson.M{"code": bson.M{"$eq": set.Code}}, set_init) - } - bar := progressbar.NewOptions(len(cards), progressbar.OptionSetWidth(50), progressbar.OptionSetDescription(fmt.Sprintf("%s, %s%s%s\t", set.ReleasedAt[0:4], Yellow, set.Code, Reset)),