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

fix: fixing pagination on facets #9443

Merged
merged 2 commits into from
Dec 4, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ create_folders:

build:
@echo "🥫 Building containers …"
${DOCKER_COMPOSE} build 2>&1
${DOCKER_COMPOSE} build ${container} 2>&1

# this is needed for CI
build_backend:
Expand Down
41 changes: 20 additions & 21 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ foreach my $file (sort keys %file_timestamps) {
# On demand exports can be very big, limit the number of products
my $export_limit = 10000;

# TODO: explain why such a high number
my $tags_page_size = 10000;

if (defined $options{export_limit}) {
Expand Down Expand Up @@ -1623,31 +1624,30 @@ sub query_list_of_tags ($request_ref, $query_ref) {
}

# groupby_tagtype
my $group_field_name = $groupby_tagtype . "_tags";
my @unwind_req = ({"\$unwind" => ("\$" . $group_field_name)},);
# specific case
if ($groupby_tagtype eq 'users') {
$group_field_name = "creator";
@unwind_req = ();
}

my $aggregate_count_parameters = [
{"\$match" => $query_ref},
{"\$unwind" => ("\$" . $groupby_tagtype . "_tags")},
{"\$group" => {"_id" => ("\$" . $groupby_tagtype . "_tags")}},
{"\$count" => ($groupby_tagtype . "_tags")}
@unwind_req,
{"\$group" => {"_id" => ("\$" . $group_field_name)}},
{"\$count" => ($group_field_name)}
];

my $aggregate_parameters = [
{"\$match" => $query_ref},
{"\$unwind" => ("\$" . $groupby_tagtype . "_tags")},
{"\$group" => {"_id" => ("\$" . $groupby_tagtype . "_tags"), "count" => {"\$sum" => 1}}},
@unwind_req,
{"\$group" => {"_id" => ("\$" . $group_field_name), "count" => {"\$sum" => 1}}},
{"\$sort" => $sort_ref},
{"\$skip" => $skip},
{"\$limit" => $limit}
];

if ($groupby_tagtype eq 'users') {
$aggregate_parameters = [
{"\$match" => $query_ref},
{"\$group" => {"_id" => ("\$creator"), "count" => {"\$sum" => 1}}},
{"\$sort" => $sort_ref}
];
}

#get cache results for aggregate query
my $key = generate_query_cache_key("aggregate", $aggregate_parameters, $request_ref);
$log->debug("MongoDB query key", {key => $key}) if $log->is_debug();
Expand Down Expand Up @@ -1746,7 +1746,7 @@ sub query_list_of_tags ($request_ref, $query_ref) {
}

if (defined $count_results) {
$request_ref->{structured_response}{count} = $count_results->{$groupby_tagtype . "_tags"};
$request_ref->{structured_response}{count} = $count_results->{$group_field_name};

if ($cache_results_flag) {
set_cache_results($key_count, $request_ref->{structured_response}{count});
Expand Down Expand Up @@ -2212,12 +2212,13 @@ sub display_list_of_tags ($request_ref, $query_ref) {
}

$html .= "</tbody></table></div>";

# if there are more than $tags_page_size lines, add pagination. Except for ?stats=1 and ?filter display
$log->info("PAGINATION: BEFORE\n");
if ( $request_ref->{structured_response}{count} >= $tags_page_size
and not(defined single_param("stats"))
and not(defined single_param("filter")))
{
$log->info("PAGINATION: CALLING\n");
$html .= "\n<hr>"
. display_pagination($request_ref, $request_ref->{structured_response}{count},
$tags_page_size, $request_ref->{page});
Expand Down Expand Up @@ -5511,6 +5512,9 @@ sub display_pagination ($request_ref, $count, $limit, $page) {
if (not defined $current_link) {
$current_link = $request_ref->{world_current_link};
}
$log->info("PAGINATION: READY\n");
my $canon_rel_url = $request_ref->{canon_rel_url} // "UNDEF";
$log->info("PAGINATION: current_link: $current_link - canon_rel_url: $canon_rel_url\n");

$log->info("current link", {current_link => $current_link}) if $log->is_info();

Expand Down Expand Up @@ -5551,12 +5555,7 @@ sub display_pagination ($request_ref, $count, $limit, $page) {

if ($current_link !~ /\?/) {
$link = $current_link;
#check if groupby_tag is used
if (defined $request_ref->{groupby_tagtype}) {
if (("/" . $request_ref->{groupby_tagtype}) ne $current_link) {
$link = $current_link . "/" . $request_ref->{groupby_tagtype};
}
}
# check if groupby_tag is used
if ($i > 1) {
$link .= "/$i";
}
Expand Down
Loading