diff --git a/backend/src/app/features/fdata.clj b/backend/src/app/features/fdata.clj index baa63f693..5370df038 100644 --- a/backend/src/app/features/fdata.clj +++ b/backend/src/app/features/fdata.clj @@ -58,28 +58,26 @@ (defn load-pointer "A database loader pointer helper" [system file-id id] - (let [{:keys [content]} (db/get system :file-data-fragment - {:id id :file-id file-id} - {::sql/columns [:content] - ::db/check-deleted false})] + (let [fragment (db/get* system :file-data-fragment + {:id id :file-id file-id} + {::sql/columns [:data]})] (l/trc :hint "load pointer" :file-id (str file-id) :id (str id) - :found (some? content)) + :found (some? fragment)) - (when-not content + (when-not fragment (ex/raise :type :internal :code :fragment-not-found :hint "fragment not found" :file-id file-id :fragment-id id)) - (blob/decode content))) + (blob/decode (:data fragment)))) (defn persist-pointers! - "Given a database connection and the final file-id, persist all - pointers to the underlying storage (the database)." + "Persist all currently tracked pointer objects" [system file-id] (let [conn (db/get-connection system)] (doseq [[id item] @pmap/*tracked*] @@ -89,7 +87,7 @@ (db/insert! conn :file-data-fragment {:id id :file-id file-id - :content content})))))) + :data content})))))) (defn process-pointers "Apply a function to all pointers on the file. Usuly used for diff --git a/backend/src/app/migrations.clj b/backend/src/app/migrations.clj index 86f0fa6f5..32768abf9 100644 --- a/backend/src/app/migrations.clj +++ b/backend/src/app/migrations.clj @@ -379,7 +379,10 @@ :fn (mg/resource "app/migrations/sql/0119-mod-file-table.sql")} {:name "0120-mod-audit-log-table" - :fn (mg/resource "app/migrations/sql/0120-mod-audit-log-table.sql")}]) + :fn (mg/resource "app/migrations/sql/0120-mod-audit-log-table.sql")} + + {:name "0121-mod-file-data-fragment-table" + :fn (mg/resource "app/migrations/sql/0121-mod-file-data-fragment-table.sql")}]) (defn apply-migrations! [pool name migrations] diff --git a/backend/src/app/migrations/sql/0121-mod-file-data-fragment-table.sql b/backend/src/app/migrations/sql/0121-mod-file-data-fragment-table.sql new file mode 100644 index 000000000..bd30e8cb8 --- /dev/null +++ b/backend/src/app/migrations/sql/0121-mod-file-data-fragment-table.sql @@ -0,0 +1,8 @@ +ALTER TABLE file_data_fragment + ADD COLUMN data bytea NULL; + +UPDATE file_data_fragment + SET data = content; + +ALTER TABLE file_data_fragment + DROP COLUMN content; diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 6c9ac43c8..4c8497693 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -327,9 +327,9 @@ [:share-id {:optional true} ::sm/uuid]]) (defn- get-file-fragment - [conn file-id fragment-id] - (some-> (db/get conn :file-data-fragment {:file-id file-id :id fragment-id}) - (update :content blob/decode))) + [cfg file-id fragment-id] + (some-> (db/get cfg :file-data-fragment {:file-id file-id :id fragment-id}) + (update :data blob/decode))) (sv/defmethod ::get-file-fragment "Retrieve a file fragment by its ID. Only authenticated users." @@ -337,12 +337,12 @@ ::rpc/auth false ::sm/params schema:get-file-fragment ::sm/result schema:file-fragment} - [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id fragment-id share-id]}] - (dm/with-open [conn (db/open pool)] - (let [perms (get-permissions conn profile-id file-id share-id)] - (check-read-permissions! perms) - (-> (get-file-fragment conn file-id fragment-id) - (rph/with-http-cache long-cache-duration))))) + [cfg {:keys [::rpc/profile-id file-id fragment-id share-id]}] + (db/run! cfg (fn [cfg] + (let [perms (get-permissions cfg profile-id file-id share-id)] + (check-read-permissions! perms) + (-> (get-file-fragment cfg file-id fragment-id) + (rph/with-http-cache long-cache-duration)))))) ;; --- COMMAND QUERY: get-project-files diff --git a/frontend/playwright/data/assets/get-file-fragment-with-assets-components.json b/frontend/playwright/data/assets/get-file-fragment-with-assets-components.json index 4f8cfb630..053031eb5 100644 --- a/frontend/playwright/data/assets/get-file-fragment-with-assets-components.json +++ b/frontend/playwright/data/assets/get-file-fragment-with-assets-components.json @@ -2,7 +2,7 @@ "~:id": "~u015fda4f-caa6-8103-8004-862a9e4b4d4b", "~:file-id": "~u015fda4f-caa6-8103-8004-862a00dd4f31", "~:created-at": "~m1718718436639", - "~:content": { + "~:data": { "~ue117f7f6-433c-807e-8004-862a38e1823d": { "~:id": "~ue117f7f6-433c-807e-8004-862a38e1823d", "~:name": "Button", @@ -28,4 +28,4 @@ "~:main-instance-page": "~u015fda4f-caa6-8103-8004-862a00ddbe94" } } -} \ No newline at end of file +} diff --git a/frontend/playwright/data/assets/get-file-fragmnet-with-assets-page.json b/frontend/playwright/data/assets/get-file-fragmnet-with-assets-page.json index 99e01ce34..bae8fd54e 100644 --- a/frontend/playwright/data/assets/get-file-fragmnet-with-assets-page.json +++ b/frontend/playwright/data/assets/get-file-fragmnet-with-assets-page.json @@ -2,7 +2,7 @@ "~:id": "~u015fda4f-caa6-8103-8004-862a9e4ad279", "~:file-id": "~u015fda4f-caa6-8103-8004-862a00dd4f31", "~:created-at": "~m1718718436639", - "~:content": { + "~:data": { "~:options": {}, "~:objects": { "~u00000000-0000-0000-0000-000000000000": { @@ -627,4 +627,4 @@ "~:id": "~u015fda4f-caa6-8103-8004-862a00ddbe94", "~:name": "Page 1" } -} \ No newline at end of file +} diff --git a/frontend/playwright/data/design/get-file-fragment-multiple-constraints.json b/frontend/playwright/data/design/get-file-fragment-multiple-constraints.json index 1a055d7d1..0fe5f6a2c 100644 --- a/frontend/playwright/data/design/get-file-fragment-multiple-constraints.json +++ b/frontend/playwright/data/design/get-file-fragment-multiple-constraints.json @@ -2,7 +2,7 @@ "~:id": "~u03bff843-920f-81a1-8004-7563acdc8ca1", "~:file-id": "~u03bff843-920f-81a1-8004-756365e1eb6a", "~:created-at": "~m1717592543081", - "~:content": { + "~:data": { "~:options": {}, "~:objects": { "~u00000000-0000-0000-0000-000000000000": { @@ -360,4 +360,4 @@ "~:id": "~u03bff843-920f-81a1-8004-756365e1eb6b", "~:name": "Page 1" } -} \ No newline at end of file +} diff --git a/frontend/playwright/data/viewer/get-file-fragment-empty-file.json b/frontend/playwright/data/viewer/get-file-fragment-empty-file.json index 544c559f7..c4fc2086e 100644 --- a/frontend/playwright/data/viewer/get-file-fragment-empty-file.json +++ b/frontend/playwright/data/viewer/get-file-fragment-empty-file.json @@ -2,7 +2,7 @@ "~:id": "~u0515a066-e303-8169-8004-73eb58e899c2", "~:file-id": "~uc7ce0794-0992-8105-8004-38f280443849", "~:created-at": "~m1717493890966", - "~:content": { + "~:data": { "~:options": {}, "~:objects": { "~u00000000-0000-0000-0000-000000000000": { @@ -94,4 +94,4 @@ "~:id": "~uc7ce0794-0992-8105-8004-38f28044384a", "~:name": "Page 1" } -} \ No newline at end of file +} diff --git a/frontend/playwright/data/viewer/get-file-fragment-single-board.json b/frontend/playwright/data/viewer/get-file-fragment-single-board.json index 8c1e62a15..cf00a2900 100644 --- a/frontend/playwright/data/viewer/get-file-fragment-single-board.json +++ b/frontend/playwright/data/viewer/get-file-fragment-single-board.json @@ -2,7 +2,7 @@ "~:id": "~udd5cc0bb-91ff-81b9-8004-77dfae2d9e7c", "~:file-id": "~udd5cc0bb-91ff-81b9-8004-77df9cd3edb1", "~:created-at": "~m1717759268004", - "~:content": { + "~:data": { "~:options": {}, "~:objects": { "~u00000000-0000-0000-0000-000000000000": { @@ -183,4 +183,4 @@ "~:id": "~udd5cc0bb-91ff-81b9-8004-77df9cd3edb2", "~:name": "Page 1" } -} \ No newline at end of file +} diff --git a/frontend/playwright/data/workspace/get-file-fragment-7760.json b/frontend/playwright/data/workspace/get-file-fragment-7760.json index 0c8011553..c07d48702 100644 --- a/frontend/playwright/data/workspace/get-file-fragment-7760.json +++ b/frontend/playwright/data/workspace/get-file-fragment-7760.json @@ -2,7 +2,7 @@ "~:id": "~ucd90e028-326a-80b4-8004-7cdeefa23ece", "~:file-id": "~ucd90e028-326a-80b4-8004-7cdec16ffad5", "~:created-at": "~m1718094617214", - "~:content": { + "~:data": { "~:options": {}, "~:objects": { "~u00000000-0000-0000-0000-000000000000": { diff --git a/frontend/playwright/data/workspace/get-file-fragment-blank.json b/frontend/playwright/data/workspace/get-file-fragment-blank.json index fe357c500..7760aaa92 100644 --- a/frontend/playwright/data/workspace/get-file-fragment-blank.json +++ b/frontend/playwright/data/workspace/get-file-fragment-blank.json @@ -2,7 +2,7 @@ "~:id": "~ude58c8f6-c5c2-8196-8004-3df9e2e52d88", "~:file-id": "~uc7ce0794-0992-8105-8004-38f280443849", "~:created-at": "~m1713873823631", - "~:content": { + "~:data": { "~:options": {}, "~:objects": { "~u00000000-0000-0000-0000-000000000000": { @@ -94,4 +94,4 @@ "~:id": "~uc7ce0794-0992-8105-8004-38f28044384a", "~:name": "Page 1" } -} \ No newline at end of file +} diff --git a/frontend/src/app/main/data/viewer.cljs b/frontend/src/app/main/data/viewer.cljs index 456413018..68757d15d 100644 --- a/frontend/src/app/main/data/viewer.cljs +++ b/frontend/src/app/main/data/viewer.cljs @@ -134,7 +134,7 @@ (uuid? share-id) (assoc :share-id share-id))] (->> (rp/cmd! :get-file-fragment params) - (rx/map :content) + (rx/map :data) (rx/map #(vector key %)))))] (->> (rp/cmd! :get-view-only-bundle params') diff --git a/frontend/src/app/main/features/pointer_map.cljs b/frontend/src/app/main/features/pointer_map.cljs index 993427e55..7055c1188 100644 --- a/frontend/src/app/main/features/pointer_map.cljs +++ b/frontend/src/app/main/features/pointer_map.cljs @@ -16,7 +16,7 @@ (letfn [(resolve-pointer [[key val :as kv]] (if (t/pointer? val) (->> (rp/cmd! :get-file-fragment {:file-id id :fragment-id @val}) - (rx/map #(get % :content)) + (rx/map #(get % :data)) (rx/map #(vector key %))) (rx/of kv)))