Skip to content

Commit

Permalink
[FIX] sieve filters management page: go throguh the list only once to…
Browse files Browse the repository at this point in the history
… optimize the load time
  • Loading branch information
kroky committed Aug 29, 2024
1 parent 7817e47 commit 43cfe9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 3 additions & 7 deletions modules/sievefilters/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function get_classic_filter_modal_content()
}

if (!hm_exists('get_mailbox_filters')) {
function get_mailbox_filters($mailbox, $site_config, $user_config, $html=false)
function get_mailbox_filters($mailbox, $site_config, $user_config)
{
$factory = get_sieve_client_factory($site_config);
try {
Expand All @@ -115,11 +115,7 @@ function get_mailbox_filters($mailbox, $site_config, $user_config, $html=false)
}
} catch (Exception $e) {
Hm_Msgs::add("ERRSieve: {$e->getMessage()}");
return !$html ? []: '';
}

if ($html == false) {
return $scripts;
return ['count' => 0, 'list' => ''];
}

$scripts_sorted = [];
Expand Down Expand Up @@ -158,7 +154,7 @@ function get_mailbox_filters($mailbox, $site_config, $user_config, $html=false)
</tr>
';
}
return $script_list;
return ['count' => count($scripts), 'list' => $script_list];
}
}

Expand Down
5 changes: 3 additions & 2 deletions modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1237,15 +1237,16 @@ protected function output() {
continue;
}
$sieve_supported++;
$num_filters = sizeof(get_mailbox_filters($mailbox, $this->get('site_config'), $this->get('user_config'), false));
$result = get_mailbox_filters($mailbox, $this->get('site_config'), $this->get('user_config'));
$num_filters = $result['count'];
$res .= '<div class="sievefilters_accounts_item">';
$res .= '<div class="sievefilters_accounts_title settings_subtitle py-2 d-flex justify-content-between border-bottom cursor-pointer">' . $mailbox['name'];
$res .= '<span class="filters_count">' . sprintf($this->trans('%s filters'), $num_filters) . '</span></div>';
$res .= '<div class="sievefilters_accounts filter_block p-3 d-none"><div class="filter_subblock">';
$res .= '<button class="add_filter btn btn-primary" account="'.$mailbox['name'].'">Add Filter</button> <button account="'.$mailbox['name'].'" class="add_script btn btn-light border">Add Script</button>';
$res .= '<table class="filter_details table my-3"><tbody>';
$res .= '<tr><th class="text-secondary fw-light col-sm-1">Priority</th><th class="text-secondary fw-light col-sm-9">Name</th><th class="text-secondary fw-light col-sm-2">Actions</th></tr>';
$res .= get_mailbox_filters($mailbox, $this->get('site_config'), $this->get('user_config'), true);
$res .= $result['list'];
$res .= '</tbody></table>';
$res .= '<div class="mb-3 d-none">
<div class="d-block">
Expand Down

0 comments on commit 43cfe9c

Please sign in to comment.