Skip to content

Commit

Permalink
fix: don't save object in memcached if it's bigger than max size
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Aug 4, 2023
1 parent fdccd42 commit 7e693a6
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,17 @@ sub get_cache_results ($key, $request_ref) {
sub set_cache_results ($key, $results) {

$log->debug("Setting value for MongoDB query key", {key => $key}) if $log->is_debug();
my $result_size = total_size($results);

# memcached max object size is 1 048 576 bytes
if ($result_size >= 1048576) {
$mongodb_log->info(
"set_cache_results - skipping - setting value - key: $key (total_size: $result_size > max size)");
return;
}

if ($mongodb_log->is_debug()) {
$mongodb_log->debug("set_cache_results - setting value - key: $key - total_size: " . total_size($results));
$mongodb_log->debug("set_cache_results - setting value - key: $key - total_size: $result_size");
}

if ($memd->set($key, $results, 3600)) {
Expand Down Expand Up @@ -4774,6 +4782,34 @@ sub add_params_to_query ($request_ref, $query_ref) {
return;
}

=head2 search_and_display_products ($request_ref, $query_ref, $sort_by, $limit, $page)
Search products and return an HTML snippet that should be included in the webpage.
=head3 Parameters
=head4 $request_ref
Reference to the internal request object.
=head4 $query_ref
Reference to the MongoDB query object.
=head4 $sort_by
A string indicating how to sort results (created_t, popularity,...), or a sorting subroutine.
=head4 $limit
Limit of the number of products to return.
=head4 $page
Requested page (first page starts at 1).
=cut

sub search_and_display_products ($request_ref, $query_ref, $sort_by, $limit, $page) {

$request_ref->{page_type} = "products";
Expand Down

0 comments on commit 7e693a6

Please sign in to comment.