summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2023-03-24 14:54:01 +0100
committerYorhel <git@yorhel.nl>2023-03-24 14:54:03 +0100
commit807cce69f0eac7767c85c592672a08af1719319a (patch)
treed4e82570acbba17d6583f04f9e7a812f69fc8fee
parent01b035b389a395eb4841653028e426cacea6c099 (diff)
Exclude unnecessary hidden DB entries from search cache
It was possible to search for deleted producers, but I didn't really see the value in that. Checking for deleted VNs is still important, likewise for tags & traits. This reduces the size of the cache a bit, but more importantly also improves accuracy of the search result counts for other DB entries.
-rw-r--r--elm/Lib/Autocomplete.elm2
-rw-r--r--elm/ProducerEdit.elm8
-rw-r--r--lib/VNWeb/Elm.pm1
-rw-r--r--lib/VNWeb/Producers/Elm.pm7
-rw-r--r--sql/func.sql9
5 files changed, 15 insertions, 12 deletions
diff --git a/elm/Lib/Autocomplete.elm b/elm/Lib/Autocomplete.elm
index e521e1e6..5b819d6d 100644
--- a/elm/Lib/Autocomplete.elm
+++ b/elm/Lib/Autocomplete.elm
@@ -147,7 +147,7 @@ vnSource =
producerSource : SourceConfig m GApi.ApiProducerResult
producerSource =
- { source = Endpoint (\s -> GP.send { search = [s], hidden = False })
+ { source = Endpoint (\s -> GP.send { search = [s] })
<| \x -> case x of
GApi.ProducerResult e -> Just e
_ -> Nothing
diff --git a/elm/ProducerEdit.elm b/elm/ProducerEdit.elm
index de2e1703..df3ea744 100644
--- a/elm/ProducerEdit.elm
+++ b/elm/ProducerEdit.elm
@@ -129,7 +129,7 @@ update msg model =
DupSubmit ->
if List.isEmpty model.dupProds
- then ({ model | state = Api.Loading }, GP.send { hidden = True, search = model.name :: Maybe.withDefault "" model.latin :: String.lines model.alias } DupResults)
+ then ({ model | state = Api.Loading }, GP.send { search = model.name :: Maybe.withDefault "" model.latin :: String.lines model.alias } DupResults)
else ({ model | dupCheck = True, dupProds = [] }, Cmd.none)
DupResults (GApi.ProducerResult prods) ->
if List.isEmpty prods
@@ -204,11 +204,7 @@ view model =
, text "The following is a list of producers that match the name(s) you gave. "
, text "Please check this list to avoid creating a duplicate producer entry. "
, text "Be especially wary of items that have been deleted! To see why an entry has been deleted, click on its title."
- , ul [] <| List.map (\p -> li []
- [ a [ href <| "/" ++ p.id ] [ text p.name ]
- , if p.hidden then b [ class "standout" ] [ text " (deleted)" ] else text ""
- ]
- ) model.dupProds
+ , ul [] <| List.map (\p -> li [] [ a [ href <| "/" ++ p.id ] [ text p.name ] ]) model.dupProds
]
, fieldset [ class "submit" ] [ submitButton (if List.isEmpty model.dupProds then "Continue" else "Continue anyway") model.state (isValid model) ]
]
diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm
index 00d21027..5506018c 100644
--- a/lib/VNWeb/Elm.pm
+++ b/lib/VNWeb/Elm.pm
@@ -113,7 +113,6 @@ our %apis = (
id => { vndbid => 'p' },
name => {},
altname => { required => 0 },
- hidden => { anybool => 1 },
} } ],
StaffResult => [ { aoh => { # Response to 'Staff'
id => { vndbid => 's' },
diff --git a/lib/VNWeb/Producers/Elm.pm b/lib/VNWeb/Producers/Elm.pm
index 8aee07e3..578ee9c8 100644
--- a/lib/VNWeb/Producers/Elm.pm
+++ b/lib/VNWeb/Producers/Elm.pm
@@ -4,15 +4,14 @@ use VNWeb::Prelude;
elm_api Producers => undef, {
search => { type => 'array', values => { searchquery => 1 } },
- hidden => { anybool => 1 },
}, sub {
my($data) = @_;
my @q = grep $_, $data->{search}->@*;
elm_ProducerResult @q ? tuwf->dbPagei({ results => 15, page => 1 },
- 'SELECT p.id, p.title[1+1] AS name, p.title[1+1+1+1] AS altname, p.hidden
- FROM', producerst, 'p', VNWeb::Validate::SearchQuery::sql_joina(\@q, 'p', 'p.id'),
- $data->{hidden} ? () : 'WHERE NOT p.hidden', '
+ 'SELECT p.id, p.title[1+1] AS name, p.title[1+1+1+1] AS altname
+ FROM', producerst, 'p', VNWeb::Validate::SearchQuery::sql_joina(\@q, 'p', 'p.id'), '
+ WHERE NOT p.hidden
ORDER BY sc.score DESC, p.sorttitle
') : [];
};
diff --git a/sql/func.sql b/sql/func.sql
index 67f2eea4..e0010d5e 100644
--- a/sql/func.sql
+++ b/sql/func.sql
@@ -27,6 +27,15 @@ CREATE OR REPLACE FUNCTION update_search_terms(objid vndbid) RETURNS SETOF recor
DECLARE
e int; -- because I'm too lazy to write out 'NULL::int' every time.
BEGIN
+ -- VN, tag & trait search needs to support finding 'hidden' items, but for
+ -- other entry types we can safely exclude those from the search cache.
+ IF (vndbid_type(objid) = 'r' AND EXISTS(SELECT 1 FROM releases WHERE hidden AND id = objid))
+ OR (vndbid_type(objid) = 'c' AND EXISTS(SELECT 1 FROM chars WHERE hidden AND id = objid))
+ OR (vndbid_type(objid) = 'p' AND EXISTS(SELECT 1 FROM producers WHERE hidden AND id = objid))
+ OR (vndbid_type(objid) = 's' AND EXISTS(SELECT 1 FROM staff WHERE hidden AND id = objid))
+ THEN RETURN;
+ END IF;
+
CASE vndbid_type(objid)
WHEN 'v' THEN RETURN QUERY
SELECT e, 3, search_norm_term(title) FROM vn_titles WHERE id = objid