summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-09-10 11:27:53 +0200
committerYorhel <git@yorhel.nl>2020-09-10 11:27:55 +0200
commit5eae77ca03f359c157460d81a2d36e91e036642f (patch)
treed6d29081de91d37578e662531e6074c8b104a79c /lib/VNDB
parentd8885e3793c5906015ccd6af52c263989ec1a76d (diff)
v2rw/filters: Add experimental validation + move compat to VNWeb
This is a minor start towards rewriting the filter logic in the new v2rw code. Filters were never validated before (I didn't have a good framework for it - now I do) and invalid filters would result in a 500. The new validation code is not yet applied, but failed validations will be logged so that I can see if it's working correctly. I mean, what better way to test than to throw it in production? I'll write new (and more flexible) SQL generation functions for these filters later, so that v2rw code can get filtered results and I can make a start on rewriting the pages that depend on the functionality. The validation schema can also be used to validate the filters stored in the DB, so I can use it to get rid of the complex handling of stored invalid filters.
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/Func.pm2
-rw-r--r--lib/VNDB/Util/Misc.pm19
2 files changed, 4 insertions, 17 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 2fcd5b54..508b2272 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -72,7 +72,7 @@ sub fil_serialize {
my @v = ref $fil->{$_} ? @{$fil->{$_}} : ($fil->{$_});
s/$e/_$fil_escape{$1}/g for(@v);
$_.'-'.join '~', @v
- } grep defined($fil->{$_}), keys %$fil;
+ } grep defined($fil->{$_}), sort keys %$fil;
}
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm
index c08fe1bb..0423e35b 100644
--- a/lib/VNDB/Util/Misc.pm
+++ b/lib/VNDB/Util/Misc.pm
@@ -40,6 +40,8 @@ sub filFetchDB {
my $filters = fil_parse $overwrite // $pref, @{$filfields{$type}};
+ VNWeb::Filters::debug_validate($type, $filters);
+
# compatibility
my $compat = $self->filCompat($type, $filters);
$self->authPref($prefname => fil_serialize $filters) if $compat && !defined $overwrite;
@@ -84,22 +86,7 @@ sub filFetchDB {
# Compatibility with old filters. Modifies the filter in-place and returns the number of changes made.
sub filCompat {
my($self, $type, $fil) = @_;
- my $mod = 0;
-
- # older tag specification (by name rather than ID)
- if($type eq 'vn' && ($fil->{taginc} || $fil->{tagexc})) {
- my $tagfind = sub {
- return map {
- my $i = $self->dbTagGet(name => $_)->[0];
- $i && $i->{searchable} ? $i->{id} : ();
- } grep $_, ref $_[0] ? @{$_[0]} : ($_[0]||'')
- };
- $fil->{tag_inc} //= [ $tagfind->(delete $fil->{taginc}) ] if $fil->{taginc};
- $fil->{tag_exc} //= [ $tagfind->(delete $fil->{tagexc}) ] if $fil->{tagexc};
- $mod++;
- }
-
- $mod;
+ $type eq 'vn' ? VNWeb::Filters::filter_vn_compat($fil) : 0
}