Skip to content

Commit cacdc0f

Browse files
committed
fix(other): apply cache-first strategy to accelerate folder browsing
1 parent c4c8033 commit cacdc0f

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ REDIS_SERVER='127.0.0.1'
5656
REDIS_PORT=6379
5757
REDIS_INDEX=1
5858
REDIS_PASS=
59-
REDIS_SOCKET=/var/run/redis/redis-server.sock
59+
REDIS_SOCKET=
6060

6161
ENABLE_MEMCACHED=true
6262
MEMCACHED_SERVER='127.0.0.1'

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454

455455
'redis_pass' => env('REDIS_PASS'),
456456

457-
'redis_socket' => env('REDIS_SOCKET', '/var/run/redis/redis-server.sock'),
457+
'redis_socket' => env('REDIS_SOCKET', ''),
458458

459459
/*
460460
| -----------------

modules/imap/handler_modules.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,25 @@ public function process() {
650650
$folder = $this->request->post['folder'];
651651
}
652652
$path = sprintf("imap_%s_%s", $form['imap_server_id'], $folder);
653-
$page_cache = $this->cache->get('imap_folders_'.$path);
653+
$with_subscription = isset($this->request->post['subscription_state']) && $this->request->post['subscription_state'];
654+
654655
if (array_key_exists('imap_prefetch', $this->request->post)) {
655656
$prefetched = $this->session->get('imap_prefetched_ids', array());
656657
$prefetched[] = $form['imap_server_id'];
657658
$this->session->set('imap_prefetched_ids', array_unique($prefetched, SORT_STRING));
658659
}
659-
$with_subscription = isset($this->request->post['subscription_state']) && $this->request->post['subscription_state'];
660+
661+
// Check cache FIRST before connecting to IMAP
662+
$page_cache = $this->cache->get('imap_folders_'.$path);
663+
if ($page_cache) {
664+
$this->out('imap_expanded_folder_data', $page_cache);
665+
$this->out('imap_expanded_folder_id', $form['imap_server_id']);
666+
$this->out('imap_expanded_folder_path', $path);
667+
$this->out('with_input', $with_subscription);
668+
$this->out('folder', $folder);
669+
return;
670+
}
671+
660672
$mailbox = Hm_IMAP_List::get_connected_mailbox($form['imap_server_id'], $this->cache);
661673
if ($mailbox && $mailbox->authed()) {
662674
$this->out('can_share_folders', stripos($mailbox->get_capability(), 'ACL') !== false);
@@ -673,14 +685,6 @@ public function process() {
673685
}
674686
}
675687
}
676-
if ($page_cache) {
677-
$this->out('imap_expanded_folder_data', $page_cache);
678-
$this->out('imap_expanded_folder_id', $form['imap_server_id']);
679-
$this->out('imap_expanded_folder_path', $path);
680-
$this->out('with_input', $with_subscription);
681-
$this->out('folder', $folder);
682-
return;
683-
}
684688
if ($mailbox && $mailbox->authed()) {
685689
$only_subscribed = $this->user_config->get('only_subscribed_folders_setting', false);
686690
if ($with_subscription) {

0 commit comments

Comments
 (0)