openfoodfacts / openfoodfacts-server

Open Food Facts database, API server and web interface - 🐪🦋 Perl, CSS and JS coders welcome 😊 For helping in Python, see Robotoff or taxonomy-editor
http://openfoodfacts.github.io/openfoodfacts-server/
GNU Affero General Public License v3.0
664 stars 392 forks source link

Refactor the update_all_products.pl script to use a new function update_existing_product_without_creating_a_new_revision() #7271

Open stephanegigandet opened 2 years ago

stephanegigandet commented 2 years ago

Problem description

The scripts/update_all_products.pl script is used to make updates to products (such as reprocessing the ingredients, recomputing scores etc.) without creating a new revision of the product. The product is updated "in place".

This code:

        # Otherwise, we silently update the .sto file of the last version
        else {

            # make sure nutrient values are numbers
            ProductOpener::Products::make_sure_numbers_are_stored_as_numbers($product_ref);

            if (!$mongodb_to_mongodb) {
                # Store data to .sto file
                store("$data_root/products/$path/product.sto", $product_ref);
            }

            # Store data to mongodb
            # Make sure product _id and code are saved as string and not a number
            # see bug #1077 - https://github.com/openfoodfacts/openfoodfacts-server/issues/1077
            # make sure that code is saved as a string, otherwise mongodb saves it as number, and leading 0s are removed
            $product_ref->{_id} .= '';
            $product_ref->{code} .= '';
            $products_collection->replace_one({"_id" => $product_ref->{_id}}, $product_ref, { upsert => 1 });
        }

Desired solution

Could be refactored and made into a new function in lib/ProductOpener/Products.pm , that we could call update_existing_product_without_creating_a_new_revision()

Similar code also exists in other scripts like scanbot.pl

Alternatives you have considered

No response

Additional context

No response

Number of products impacted

No response

Time per product

No response

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity.