From 37a2806f0390479900084fa657ec6a4b6c18dcca Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 15 Mar 2023 22:41:45 +0000 Subject: [PATCH] api, backend: improve references uses --- lib/PoorBooru/API/V0/Controller/Media.pm | 4 ++-- lib/PoorBooru/API/V0/Controller/Tags.pm | 10 +++++----- lib/PoorBooru/Backend/Controller/Gallery.pm | 2 +- lib/PoorBooru/Backend/Controller/Tags.pm | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/PoorBooru/API/V0/Controller/Media.pm b/lib/PoorBooru/API/V0/Controller/Media.pm index 7558760..20e2124 100644 --- a/lib/PoorBooru/API/V0/Controller/Media.pm +++ b/lib/PoorBooru/API/V0/Controller/Media.pm @@ -21,14 +21,14 @@ sub list ($self) ) if $v->has_error; my $paged_media = $self->schema->resultset("Media") - ->search({}, $MEDIA_SEARCH_OPTS)->page($page); + ->search(undef, { $MEDIA_SEARCH_OPTS->%* })->page($page); my @media = map +{ media_id => $_->media_id, seaweedfs_fid => $_->seaweedfs_fid, }, $paged_media->all; return $self->render(json => { - media => \@media, + media => [ @media ], pager => { $self->pager($paged_media->pager) }, }); }; diff --git a/lib/PoorBooru/API/V0/Controller/Tags.pm b/lib/PoorBooru/API/V0/Controller/Tags.pm index 7452bd3..2354682 100644 --- a/lib/PoorBooru/API/V0/Controller/Tags.pm +++ b/lib/PoorBooru/API/V0/Controller/Tags.pm @@ -25,7 +25,7 @@ sub list ($self) ) if $v->has_error; my $paged_tags = $self->schema->resultset("TagCountView") - ->search(undef, $TAGS_COUNT_VIEW_SEARCH_OPTS)->page($page); + ->search(undef, { $TAGS_COUNT_VIEW_SEARCH_OPTS->%* })->page($page); my @tags = map +{ id => $_->tag_id, name => $_->name, @@ -33,7 +33,7 @@ sub list ($self) }, $paged_tags->all; return $self->render(json => { - tags => \@tags, + tags => [ @tags ], pager => { $self->pager($paged_tags->pager) }, }); }; @@ -57,7 +57,7 @@ sub show ($self) push @search, { name => $tag_id_or_name }; } - my $tag = $self->schema->resultset("Tag")->single(\@search); + my $tag = $self->schema->resultset("Tag")->single([ @search ]); return $self->render( json => {error => "Tag not found"}, @@ -65,7 +65,7 @@ sub show ($self) ) if !defined($tag); my $paged_media = $self->schema->resultset("TaggedMediaView") - ->search({ tag_id => $tag->tag_id }, $MEDIA_SEARCH_OPTS) + ->search({ tag_id => $tag->tag_id }, { $MEDIA_SEARCH_OPTS->%* }) ->page($page); my @media = map +{ media_id => $_->media_id, @@ -75,7 +75,7 @@ sub show ($self) return $self->render(json => { id => $tag->tag_id, name => $tag->name, - media => \@media, + media => [ @media ], pager => { $self->pager($paged_media->pager) }, }); }; diff --git a/lib/PoorBooru/Backend/Controller/Gallery.pm b/lib/PoorBooru/Backend/Controller/Gallery.pm index b1c221d..b2033cb 100644 --- a/lib/PoorBooru/Backend/Controller/Gallery.pm +++ b/lib/PoorBooru/Backend/Controller/Gallery.pm @@ -30,7 +30,7 @@ sub index ($self) return $self->render( template => "gallery", - media => \@media, + media => [ @media ], pager => { $self->pager_links($res->json->{pager}) }, ); }; diff --git a/lib/PoorBooru/Backend/Controller/Tags.pm b/lib/PoorBooru/Backend/Controller/Tags.pm index 2f080be..9be07f5 100644 --- a/lib/PoorBooru/Backend/Controller/Tags.pm +++ b/lib/PoorBooru/Backend/Controller/Tags.pm @@ -28,7 +28,7 @@ sub list ($self) return $self->render( template => "tags", - tags => \@tags, + tags => [ @tags ], pager => { $self->pager_links($res->json->{pager}) }, ); }; @@ -57,7 +57,7 @@ sub show ($self) return $self->render( template => "gallery", - media => \@media, + media => [ @media ], pager => { $self->pager_links($res->json->{pager}) }, ); };