Skip to content

refactor(backend): improve block page performance by reusing Sieve connections - #1604

Draft
Shadow243 wants to merge 1 commit into
cypht-org:masterfrom
Shadow243:refactor-block-list
Draft

Shadow243 wants to merge 1 commit into
cypht-org:masterfrom
Shadow243:refactor-block-list

Conversation

@Shadow243

Copy link
Copy Markdown
Member

As discussed with @kroky via telegram, we aim to minimize the number of Sieve server reconnections to improve the block page performance.

@Shadow243
Shadow243 marked this pull request as draft August 9, 2025 00:14
Comment thread modules/sievefilters/functions.php Outdated
@Shadow243
Shadow243 force-pushed the refactor-block-list branch 3 times, most recently from 760827b to 115c4e1 Compare August 25, 2025 19:45
@Shadow243

Copy link
Copy Markdown
Member Author

@kroky this is now working with Postale. Could you please review it when you have a chance?

Comment thread modules/sievefilters/hm-sieve-pool.php Outdated
Comment thread modules/sievefilters/hm-sieve-pool.php Outdated
Comment thread modules/sievefilters/hm-sieve-pool.php Outdated
Comment thread modules/sievefilters/hm-sieve-pool.php Outdated
@Shadow243
Shadow243 force-pushed the refactor-block-list branch 8 times, most recently from 29f0f60 to 1a64c68 Compare September 7, 2025 01:09
Comment thread modules/sievefilters/modules.php Outdated
$servers[$id] = $s;
}
}
SieveService::init($this->cache, $servers);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can init once in a module and reuse the module whenever you need it.

Comment thread modules/sievefilters/README.md Outdated
@Shadow243
Shadow243 force-pushed the refactor-block-list branch 3 times, most recently from 7a54a6e to 6c368a4 Compare September 11, 2025 23:53
@Shadow243
Shadow243 force-pushed the refactor-block-list branch 6 times, most recently from 1965bf7 to 069b879 Compare September 13, 2025 02:00
@Shadow243
Shadow243 force-pushed the refactor-block-list branch 4 times, most recently from ed606d9 to b9d33c2 Compare September 13, 2025 03:08
@Shadow243

Copy link
Copy Markdown
Member Author

@christer77 @Baraka24 @IrAlfred I've implemented some enhancements on the block_list page. Please take some time to test them before @kroky proceeds with the review.

@Shadow243
Shadow243 marked this pull request as ready for review September 16, 2025 17:18
@Baraka24

Copy link
Copy Markdown
Member

Thanks @Shadow243 for this big work, we took the time to test differently and here are what we fund:

  • when at ?page=block_list, and connecting with IMAP SESSION_TYPE(.env configured IMAP to log in), we were getting :
Sieve: Failed to get Sieve scripts for server '68b9aa55b0378': Socket creation failed: php_network_getaddresses: getaddrinfo for tls failed: Temporary failure in name resolution

We expected that this should be coming from tls config along side IMAP_AUTH_TLS, then we tried to connect using DB SESSION_TYPE, and here trying to login(no account configured) we got:

- Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, false given in /var/www/html/cypht/modules/sievefilters/functions.php:19
Stack trace:
#0 /var/www/html/cypht/modules/sievefilters/functions.php(19): array_filter()
#1 /var/www/html/cypht/modules/sievefilters/modules.php(64): ensure_sieve_service_initialized()
#2 /var/www/html/cypht/lib/modules_exec.php(177): Hm_Handler_sieve_filters_enabled->process()
#3 /var/www/html/cypht/lib/modules_exec.php(155): Hm_Module_Exec->run_handler_module()
#4 /var/www/html/cypht/lib/dispatch.php(218): Hm_Module_Exec->run_handler_modules()
#5 /var/www/html/cypht/lib/dispatch.php(188): Hm_Dispatch->process_request()
#6 /var/www/html/cypht/index.php(55): Hm_Dispatch->__construct()
#7 {main}
  thrown in /var/www/html/cypht/modules/sievefilters/functions.php on line 19
  • note also, only unblock sender action is working at ?page=block_list, other ones are not working.

@Baraka24

Copy link
Copy Markdown
Member

One more thing to note, please deal with caches, it is likely the updated block_list content are cached, to see updates we have to clear all caches, logout and login again the find the updates as well. Please check also as this a part of performance.

@Shadow243

Copy link
Copy Markdown
Member Author

Thanks @Shadow243 for this big work, we took the time to test differently and here are what we fund:

  • when at ?page=block_list, and connecting with IMAP SESSION_TYPE(.env configured IMAP to log in), we were getting :
Sieve: Failed to get Sieve scripts for server '68b9aa55b0378': Socket creation failed: php_network_getaddresses: getaddrinfo for tls failed: Temporary failure in name resolution

We expected that this should be coming from tls config along side IMAP_AUTH_TLS, then we tried to connect using DB SESSION_TYPE, and here trying to login(no account configured) we got:

- Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, false given in /var/www/html/cypht/modules/sievefilters/functions.php:19
Stack trace:
#0 /var/www/html/cypht/modules/sievefilters/functions.php(19): array_filter()
#1 /var/www/html/cypht/modules/sievefilters/modules.php(64): ensure_sieve_service_initialized()
#2 /var/www/html/cypht/lib/modules_exec.php(177): Hm_Handler_sieve_filters_enabled->process()
#3 /var/www/html/cypht/lib/modules_exec.php(155): Hm_Module_Exec->run_handler_module()
#4 /var/www/html/cypht/lib/dispatch.php(218): Hm_Module_Exec->run_handler_modules()
#5 /var/www/html/cypht/lib/dispatch.php(188): Hm_Dispatch->process_request()
#6 /var/www/html/cypht/index.php(55): Hm_Dispatch->__construct()
#7 {main}
  thrown in /var/www/html/cypht/modules/sievefilters/functions.php on line 19
  • note also, only unblock sender action is working at ?page=block_list, other ones are not working.

Fixed 7a0bea3

@marclaporte

Copy link
Copy Markdown
Member

@Shadow243 This branch has conflicts that must be resolved

@Shadow243
Shadow243 force-pushed the refactor-block-list branch 3 times, most recently from 89223e3 to d610249 Compare May 7, 2026 02:57
@Shadow243

Copy link
Copy Markdown
Member Author

Thanks @Shadow243 for this big work, we took the time to test differently and here are what we fund:

  • when at ?page=block_list, and connecting with IMAP SESSION_TYPE(.env configured IMAP to log in), we were getting :
Sieve: Failed to get Sieve scripts for server '68b9aa55b0378': Socket creation failed: php_network_getaddresses: getaddrinfo for tls failed: Temporary failure in name resolution

We expected that this should be coming from tls config along side IMAP_AUTH_TLS, then we tried to connect using DB SESSION_TYPE, and here trying to login(no account configured) we got:

- Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, false given in /var/www/html/cypht/modules/sievefilters/functions.php:19
Stack trace:
#0 /var/www/html/cypht/modules/sievefilters/functions.php(19): array_filter()
#1 /var/www/html/cypht/modules/sievefilters/modules.php(64): ensure_sieve_service_initialized()
#2 /var/www/html/cypht/lib/modules_exec.php(177): Hm_Handler_sieve_filters_enabled->process()
#3 /var/www/html/cypht/lib/modules_exec.php(155): Hm_Module_Exec->run_handler_module()
#4 /var/www/html/cypht/lib/dispatch.php(218): Hm_Module_Exec->run_handler_modules()
#5 /var/www/html/cypht/lib/dispatch.php(188): Hm_Dispatch->process_request()
#6 /var/www/html/cypht/index.php(55): Hm_Dispatch->__construct()
#7 {main}
  thrown in /var/www/html/cypht/modules/sievefilters/functions.php on line 19
  • note also, only unblock sender action is working at ?page=block_list, other ones are not working.

@Baraka24 everything should work now.

@Shadow243
Shadow243 requested a review from kroky May 9, 2026 12:17
@Baraka24

Copy link
Copy Markdown
Member

@Shadow243 Thanks. I tried and it worked.
To @kroky to rerview

* Service orchestrator - combines cache and connection management
* This provides backward compatibility and clean API
*/
class SieveService

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You combine several very different classes in the same file which is quite confusing.

Also, the way we now use phpsievemanager is quite from obvious. It was purposefully designed as an external repo to handle sieve-related connection and interaction. Now we add so much sieve-related connection functionality directly in Cypht. I think we should add all that caching and changes to the php-sieve-manager repo and then keep cypht lightweight - just reuse.

Also, I don't like the fact that we got rid of the client factory - that is reused in Tiki and overridden there, so we will have even more changes to do.

In short, something simple to add like caching resulting in too much boilerplate here. I think we should greatly simplify the current approach. Add simple caching in php-sieve-manager. Bring back the factory and client usage. Add global modules that run on every sieve request rather than calls to methods like ensure_sieve_service_initialized in random list of modules. I don't even think we should have that method - the factory and client usage should be enough - it initializes once, keep cached version, return cached version when requested. No sieve module methods need changes in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, I will push required changes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shadow243
Shadow243 force-pushed the refactor-block-list branch from 0bd5410 to b6e2313 Compare June 13, 2026 08:20
@Shadow243
Shadow243 force-pushed the refactor-block-list branch 4 times, most recently from c7451ab to 2f7d755 Compare June 26, 2026 19:46
Comment thread modules/sievefilters/modules.php Outdated
$factory = get_sieve_client_factory($this->config);
try {
$client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux'));
$client = get_sieve_client($imap_account, $this->config, $this->cache);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be too many changes in this MR not related to the purpose of reusing connections. Why do we get rid of the client factory? It was reused in Tiki and is a good pattern. Sometimes the client factory returns one class, sometimes another one. You could achieve the same result by modifying the client factory implementation is Cypht and reusing the connections via the cache. Why all these changes in the modules? I'd like to see a severely trimmed down version of a diff here just introducing the caching of connections change... note that you can cache the result of a client factory init and return the same client no matter how many times it is called...

@Shadow243
Shadow243 force-pushed the refactor-block-list branch from 2f7d755 to 74f5a9a Compare June 30, 2026 21:40
@Shadow243
Shadow243 force-pushed the refactor-block-list branch from 74f5a9a to 163a2ea Compare June 30, 2026 21:42
@marclaporte
marclaporte marked this pull request as draft July 20, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants