From f14d0a4590c928b96eef23d9541a7ee4226f9211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Tue, 25 Jul 2023 17:03:11 +0200 Subject: [PATCH] fix: use states_tags index for remove_empty_products.pl (#8728) the script was timing out because it used the "empty" field for which we don't have an index also removed useless cruft --- scripts/remove_empty_products.pl | 43 +++++--------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/scripts/remove_empty_products.pl b/scripts/remove_empty_products.pl index 71915c622e3c2..67324b5f26cf1 100755 --- a/scripts/remove_empty_products.pl +++ b/scripts/remove_empty_products.pl @@ -20,41 +20,19 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -use Modern::Perl '2017'; -use utf8; +use ProductOpener::PerlStandards; use CGI::Carp qw(fatalsToBrowser); use ProductOpener::Config qw/:all/; -use ProductOpener::Store qw/:all/; -use ProductOpener::Index qw/:all/; -use ProductOpener::Display qw/:all/; -use ProductOpener::Tags qw/:all/; -use ProductOpener::Users qw/:all/; -use ProductOpener::Images qw/:all/; -use ProductOpener::Lang qw/:all/; -use ProductOpener::Mail qw/:all/; use ProductOpener::Products qw/:all/; -use ProductOpener::Food qw/:all/; -use ProductOpener::Ingredients qw/:all/; -use ProductOpener::Images qw/:all/; +use ProductOpener::Store qw/:all/; use ProductOpener::Data qw/:all/; -use CGI qw/:cgi :form escapeHTML/; -use URI::Escape::XS; -use Storable qw/dclone/; -use Encode; -use JSON::PP; - -# Get a list of all products - -my $total = 0; -my $l = 'en'; +# This script is run daily to remove empty products (without data or pictures) +# in particular products created by the button to add a product without a barcode -$lc = $l; -$lang = $l; - -my $cursor = get_products_collection()->query({empty => 1})->fields({code => 1, empty => 1}); +my $cursor = get_products_collection()->query({states_tags => "en:empty"})->fields({code => 1, empty => 1}); $cursor->immortal(1); my $removed = 0; @@ -68,18 +46,12 @@ if ((defined $product_ref) and ($code ne '')) { - $lc = $product_ref->{lc}; - $lang = $lc; - if (($product_ref->{empty} == 1) and (time() > $product_ref->{last_modified_t} + 86400)) { $product_ref->{deleted} = 'on'; my $comment = "automatic removal of product without information or images"; print STDERR "removing product code $code\n"; $removed++; - if ($lc ne 'xx') { - store_product($User_id, $product_ref, $comment); - } } } else { @@ -88,10 +60,7 @@ } -print STDERR "$lc - removed $removed products\n"; -$total += $removed; - -print STDERR "total - removed $total products\n"; +print STDERR "removed $removed products\n"; exit(0);