From 61a66f31ab1be963e90970dd9ae8c5894aa7d5c7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 19 Oct 2026 15:22:10 +0000 Subject: [PATCH] :ambulance: Disable media storage quota check on upload Comment out the media-storage-bytes-per-team check in upload-file-media-object. The SUM over storage_object takes 3-12s per upload on prod (3.5TB DB, ~34 slow runs/hour) and blocks uploads. Keep the SQL and quote definition for re-enable with a cheaper implementation. Update the upload quota test to document the disabled state until the new implementation lands. AI-assisted-by: muse-spark-1.3-contributor --- backend/src/app/rpc/commands/media.clj | 27 ++++++++++++------- .../test/backend_tests/rpc_quotes_test.clj | 11 ++++---- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/backend/src/app/rpc/commands/media.clj b/backend/src/app/rpc/commands/media.clj index 99d5daea5a..ce75f53994 100644 --- a/backend/src/app/rpc/commands/media.clj +++ b/backend/src/app/rpc/commands/media.clj @@ -40,11 +40,13 @@ (declare create-file-media-object) -(def ^:private sql:get-team-id-for-file - "SELECT p.team_id - FROM file AS f - JOIN project AS p ON (p.id = f.project_id) - WHERE f.id = ?") +;; TEMPORARILY DISABLED (2026-10-19): only used by the disabled +;; media-storage-bytes-per-team quote check below. Kept for re-enable. +;; (def ^:private sql:get-team-id-for-file +;; "SELECT p.team_id +;; FROM file AS f +;; JOIN project AS p ON (p.id = f.project_id) +;; WHERE f.id = ?") (def ^:private schema:upload-file-media-object [:map {:title "upload-file-media-object"} @@ -64,11 +66,16 @@ (media.v/validate-media-type! content) (media.v/validate-media-size! content) - (let [team-id (:team-id (db/exec-one! pool [sql:get-team-id-for-file file-id]))] - (quotes/check! cfg {::quotes/id ::quotes/media-storage-bytes-per-team - ::quotes/profile-id profile-id - ::quotes/team-id team-id - ::quotes/incr (:size content)})) + ;; TEMPORARILY DISABLED (2026-10-19): media-storage-bytes-per-team + ;; quote performs a full SUM over storage_object per upload (3-12s in + ;; prod on a 3.5TB DB, ~34 slow executions/hour). Disabled until we + ;; land a cheaper approximation (cached counter / rewritten query). + ;; TODO: re-enable with the new implementation. + ;; (let [team-id (:team-id (db/exec-one! pool [sql:get-team-id-for-file file-id]))] + ;; (quotes/check! cfg {::quotes/id ::quotes/media-storage-bytes-per-team + ;; ::quotes/profile-id profile-id + ;; ::quotes/team-id team-id + ;; ::quotes/incr (:size content)})) (db/run! cfg (fn [{:keys [::db/conn] :as cfg}] ;; We get the minimal file for proper checking if diff --git a/backend/test/backend_tests/rpc_quotes_test.clj b/backend/test/backend_tests/rpc_quotes_test.clj index b0740f1b22..ab6b8ede9f 100644 --- a/backend/test/backend_tests/rpc_quotes_test.clj +++ b/backend/test/backend_tests/rpc_quotes_test.clj @@ -442,6 +442,7 @@ (t/is (true? true) "deduped storage counted once, under quota")))) (t/deftest media-upload-enforces-storage-quote + ;; TEMPORARILY DISABLED (2026-10-19), see body. (with-mocks [mock {:target 'app.config/get :return (th/config-get-mock {:quotes-media-storage-bytes-per-team 100})}] @@ -466,12 +467,10 @@ out (th/command! params)] - ;; 312043 bytes > 100 byte limit → should be rejected - (t/is (not (th/success? out))) - (let [error (:error out)] - (t/is (= :restriction (th/ex-type error))) - (t/is (= :max-quote-reached (th/ex-code error))) - (t/is (= "media-storage-bytes-per-team" (:target (ex-data error)))))))) + ;; TEMPORARILY DISABLED (2026-10-19): upload path no longer checks + ;; media-storage-bytes-per-team, so even over quota the upload + ;; succeeds. TODO: restore rejection with cheaper implementation. + (t/is (th/success? out))))) ;; --- SNAPSHOTS (VERSIONS) QUOTES