Skip to content

Commit

Permalink
fix: use states_tags index for remove_empty_products.pl (#8728)
Browse files Browse the repository at this point in the history
the script was timing out because it used the "empty" field for which we don't have an index
also removed useless cruft
  • Loading branch information
stephanegigandet authored Jul 25, 2023
1 parent b128504 commit f14d0a4
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions scripts/remove_empty_products.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,19 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

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;

Expand All @@ -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 {
Expand All @@ -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);

0 comments on commit f14d0a4

Please sign in to comment.