From 6d6b225ef46f263e245c1c1af84d2d3f44c2b311 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Sat, 3 Mar 2018 15:47:20 +0100
Subject: [PATCH] Implementing timeout options

---
 database/Config.php                        | 3 +++
 database/backends/PostgresSmartBackend.php | 3 ++-
 qrs_config.default.php                     | 4 +++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/database/Config.php b/database/Config.php
index 8779ea4..b463be2 100644
--- a/database/Config.php
+++ b/database/Config.php
@@ -29,6 +29,9 @@ class Config
         $options = [];
         if (defined(qrs_db_option_tsqueryfunction) && null !== qrs_db_option_tsqueryfunction)
             $options['tsqueryfunction'] = qrs_db_option_tsqueryfunction;
+
+        $options['timeout'] = (defined(qrs_db_option_timeout) && null !== qrs_db_option_timeout) ? qrs_db_option_timeout : 5000;
+
         if (defined(qrs_db_connector) && null !== qrs_db_connector)
             return new Config(qrs_path_prefix, qrs_db_connector, qrs_db_user, qrs_db_pass, qrs_backend, $options);
         else
diff --git a/database/backends/PostgresSmartBackend.php b/database/backends/PostgresSmartBackend.php
index 7c825c9..e08a1ca 100644
--- a/database/backends/PostgresSmartBackend.php
+++ b/database/backends/PostgresSmartBackend.php
@@ -12,7 +12,8 @@ class PostgresSmartBackend implements Backend
     function __construct(\PDO $db, array $options)
     {
         $this->db = $db;
-        $this->db->exec("SET statement_timeout = 5000;");
+        $timeout = $options["timeout"];
+        $this->db->exec("SET statement_timeout = $timeout;");
         $this->options = $options;
     }
 
diff --git a/qrs_config.default.php b/qrs_config.default.php
index 95539f3..5bc6425 100644
--- a/qrs_config.default.php
+++ b/qrs_config.default.php
@@ -3,13 +3,15 @@ define('qrs_db_host', 'example.com');
 define('qrs_db_port', 5432);
 define('qrs_db_name', 'quassel');
 
-//Only change this if you know what you are doing
+// Only change this if you know what you are doing
 define('qrs_db_connector', null);
 
 define('qrs_db_user', 'quassel');
 define('qrs_db_pass', 'password');
 
 define('qrs_db_option_tsqueryfunction', "plainto_tsquery('english', :query)");
+// Timeout in milliseconds
+define('qrs_db_option_timeout', 5000);
 
 define('qrs_backend', 'pgsql-smart');
 
-- 
GitLab