From c283e170ac5eee1a060656a3fd44dfd984c5e7f2 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Thu, 5 Jan 2023 17:31:32 +0000
Subject: [PATCH] feat(mastodon): Database prepare statements

Cherry-Pick of https://patch-diff.githubusercontent.com/raw/mastodon/chart/pull/5.patch

[PATCH] Add the PREPARED_STATEMENTS environment variable and set it
 to its default value Being able to control it can be useful in situations
 where prepared statements don't work as expected. Once such case can be
 pgbouncer as provided by DigitalOcean for connection pooling.

Co-authored-by: Cees-Jan Kiewiet <ceesjank@gmail.com>
---
 charts/mastodon/README.md                    | 9 +++++----
 charts/mastodon/templates/configmap-env.yaml | 1 +
 charts/mastodon/values.yaml                  | 3 +++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/charts/mastodon/README.md b/charts/mastodon/README.md
index a5187be30..50f16186f 100644
--- a/charts/mastodon/README.md
+++ b/charts/mastodon/README.md
@@ -1,6 +1,6 @@
 # mastodon
 
-![Version: 3.0.7](https://img.shields.io/badge/Version-3.0.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v3.5.5](https://img.shields.io/badge/AppVersion-v3.5.5-informational?style=flat-square)
+![Version: 3.0.8](https://img.shields.io/badge/Version-3.0.8-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v3.5.5](https://img.shields.io/badge/AppVersion-v3.5.5-informational?style=flat-square)
 
 Mastodon is a free, open-source social network server based on ActivityPub.
 
@@ -17,7 +17,7 @@ Mastodon is a free, open-source social network server based on ActivityPub.
 |------------|------|---------|
 | https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami | elasticsearch | 19.0.1 |
 | https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami | postgresql | 11.1.3 |
-| https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami | redis | 16.13.2 |
+| https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami | redis | 17.3.14 |
 
 ## Values
 
@@ -32,7 +32,7 @@ Mastodon is a free, open-source social network server based on ActivityPub.
 | externalAuth.pam.enabled | bool | `false` |  |
 | externalAuth.saml.enabled | bool | `false` |  |
 | image.pullPolicy | string | `"IfNotPresent"` |  |
-| image.repository | string | `"tootsuite/mastodon"` |  |
+| image.repository | string | `"docker.io/tootsuite/mastodon"` |  |
 | image.tag | string | `""` |  |
 | ingress.annotations | string | `nil` |  |
 | ingress.enabled | bool | `true` |  |
@@ -52,6 +52,7 @@ Mastodon is a free, open-source social network server based on ActivityPub.
 | mastodon.persistence.assets.resources.requests.storage | string | `"10Gi"` |  |
 | mastodon.persistence.system.accessMode | string | `"ReadWriteOnce"` |  |
 | mastodon.persistence.system.resources.requests.storage | string | `"100Gi"` |  |
+| mastodon.preparedStatements | bool | `true` | Sets the PREPARED_STATEMENTS environment variable: https://docs.joinmastodon.org/admin/config/#prepared_statements |
 | mastodon.s3.access_key | string | `""` |  |
 | mastodon.s3.access_secret | string | `""` |  |
 | mastodon.s3.alias_host | string | `""` | If you have a caching proxy, enter its base URL here. |
@@ -73,7 +74,7 @@ Mastodon is a free, open-source social network server based on ActivityPub.
 | mastodon.sidekiq.workers[0].affinity | object | `{}` | Affinity for this specific deployment, overwrites .Values.affinity and .Values.mastodon.sidekiq.affinity |
 | mastodon.sidekiq.workers[0].concurrency | int | `25` | Number of threads / parallel sidekiq jobs that are executed per Pod |
 | mastodon.sidekiq.workers[0].name | string | `"all-queues"` |  |
-| mastodon.sidekiq.workers[0].queues | list | `["default","push","mailers","pull","scheduler"]` | Sidekiq queues for Mastodon that are handled by this worker. See https://docs.joinmastodon.org/admin/scaling/#concurrency See https://github.com/mperham/sidekiq/wiki/Advanced-Options#queues for how to weight queues as argument |
+| mastodon.sidekiq.workers[0].queues | list | `["default,8","push,6","mailers,2","pull","scheduler"]` | Sidekiq queues for Mastodon that are handled by this worker. See https://docs.joinmastodon.org/admin/scaling/#concurrency See https://github.com/mperham/sidekiq/wiki/Advanced-Options#queues for how to weight queues as argument |
 | mastodon.sidekiq.workers[0].replicas | int | `1` | Number of Pod replicas deployed by the Deployment |
 | mastodon.sidekiq.workers[0].resources | object | `{}` | Resources for this specific deployment to allow optimised scaling, overwrites .Values.mastodon.sidekiq.resources |
 | mastodon.singleUserMode | bool | `false` | If set to true, the frontpage of your Mastodon server will always redirect to the first profile in the database and registrations will be disabled. |
diff --git a/charts/mastodon/templates/configmap-env.yaml b/charts/mastodon/templates/configmap-env.yaml
index 4d0195568..3fe6fda9c 100644
--- a/charts/mastodon/templates/configmap-env.yaml
+++ b/charts/mastodon/templates/configmap-env.yaml
@@ -15,6 +15,7 @@ data:
   DB_NAME: {{ .Values.postgresql.auth.database }}
   DB_POOL: {{ include "mastodon.maxDbPool" . }}
   DB_USER: {{ .Values.postgresql.auth.username }}
+  PREPARED_STATEMENTS: {{ .Values.mastodon.preparedStatements | quote }}
   DEFAULT_LOCALE: {{ .Values.mastodon.locale }}
   {{- if .Values.elasticsearch.enabled }}
   ES_ENABLED: "true"
diff --git a/charts/mastodon/values.yaml b/charts/mastodon/values.yaml
index 846b28caa..1615c3b3d 100644
--- a/charts/mastodon/values.yaml
+++ b/charts/mastodon/values.yaml
@@ -192,6 +192,9 @@ mastodon:
       # -- Enable statsd publishing via STATSD_ADDR environment variable
       address: ""
 
+  # -- Sets the PREPARED_STATEMENTS environment variable: https://docs.joinmastodon.org/admin/config/#prepared_statements
+  preparedStatements: true
+
 ingress:
   enabled: true
   annotations:
-- 
GitLab