Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stephanegigandet opened this issue Aug 29, 2022 · 1 comment · May be fixed by #8263
Labels
refactor ⏰ Stale This issue hasn't seen activity in a while. You can try documenting more to unblock it.

Comments

@stephanegigandet
Copy link
Contributor

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

@stephanegigandet stephanegigandet added ✨ Feature Features or enhancements to Open Food Facts server refactor labels Aug 29, 2022
@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the ⏰ Stale This issue hasn't seen activity in a while. You can try documenting more to unblock it. label Nov 28, 2022
@teolemon teolemon moved this to To discuss and validate in 🍊 Open Food Facts Server issues Apr 23, 2024
@teolemon teolemon removed the ✨ Feature Features or enhancements to Open Food Facts server label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor ⏰ Stale This issue hasn't seen activity in a while. You can try documenting more to unblock it.
Projects
Status: To discuss and validate
2 participants