From ed785123d183d4995787aa2820e907bdf45a5b83 Mon Sep 17 00:00:00 2001 From: siliconfeces <124937394+siliconfeces@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:30:09 +0200 Subject: [PATCH] Remove duplicate tags when updating DB --- lib/LANraragi/Utils/Database.pm | 5 ++++- lib/LANraragi/Utils/Tags.pm | 6 +++++- tools/cpanfile | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/LANraragi/Utils/Database.pm b/lib/LANraragi/Utils/Database.pm index 32897cb84..370a7b709 100644 --- a/lib/LANraragi/Utils/Database.pm +++ b/lib/LANraragi/Utils/Database.pm @@ -15,10 +15,11 @@ use File::Path qw(remove_tree); use Redis; use Cwd; use Unicode::Normalize; +use List::MoreUtils qw(uniq); use LANraragi::Utils::Generic qw(flat); use LANraragi::Utils::String qw(trim trim_CRLF trim_url); -use LANraragi::Utils::Tags qw(unflat_tagrules tags_rules_to_array restore_CRLF); +use LANraragi::Utils::Tags qw(unflat_tagrules tags_rules_to_array restore_CRLF join_tags_to_string split_tags_to_array ); use LANraragi::Utils::Archive qw(get_filelist); use LANraragi::Utils::Logging qw(get_logger); @@ -390,6 +391,8 @@ sub set_tags ( $id, $newtags, $append = 0 ) { } } + $newtags = join_tags_to_string(uniq(split_tags_to_array($newtags))); + # Update sets depending on the added/removed tags update_indexes( $id, $oldtags, $newtags ); diff --git a/lib/LANraragi/Utils/Tags.pm b/lib/LANraragi/Utils/Tags.pm index 602b98377..9b2a131e4 100644 --- a/lib/LANraragi/Utils/Tags.pm +++ b/lib/LANraragi/Utils/Tags.pm @@ -10,7 +10,7 @@ use LANraragi::Utils::String qw(trim trim_CRLF); # Functions related to the Tag system. use Exporter 'import'; -our @EXPORT_OK = qw( unflat_tagrules replace_CRLF restore_CRLF tags_rules_to_array rewrite_tags split_tags_to_array ); +our @EXPORT_OK = qw( unflat_tagrules replace_CRLF restore_CRLF tags_rules_to_array rewrite_tags split_tags_to_array join_tags_to_string ); sub is_null_or_empty { return !length(shift); @@ -47,6 +47,10 @@ sub split_tags_to_array { return @tags; } +sub join_tags_to_string { + return join( ',', @_ ); +} + sub tags_rules_to_array { my ($text_rules) = @_; my @rules; diff --git a/tools/cpanfile b/tools/cpanfile index 4964b8266..0d9156d16 100755 --- a/tools/cpanfile +++ b/tools/cpanfile @@ -8,6 +8,7 @@ requires 'Encode', 3.01; requires 'Archive::Libarchive::Extract', 0.03; requires 'Archive::Libarchive::Peek', 0.04; requires 'Digest::SHA', 6.02; +requires 'List::MoreUtils', 0.430; # Not required by LRR itself but needs this version for Alpine support requires 'Crypt::Rijndael', 1.14;