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

Remove duplicate tags when updating DB #871

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/LANraragi/Utils/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 );

Expand Down
6 changes: 5 additions & 1 deletion lib/LANraragi/Utils/Tags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down