Skip to content

Commit 7011546

Browse files
gautamg795Convex, Inc.
authored and
Convex, Inc.
committed
file storage refactor
GitOrigin-RevId: 1e654aaf7ca1ea7297c37cdcea193f6aae850f1f
1 parent 59d4f96 commit 7011546

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

crates/application/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ use model::{
200200
},
201201
ExternalPackagesModel,
202202
},
203-
file_storage::FileStorageId,
203+
file_storage::{
204+
types::FileStorageEntry,
205+
FileStorageId,
206+
},
204207
modules::{
205208
module_versions::{
206209
AnalyzedModule,
@@ -2193,6 +2196,17 @@ impl<RT: Runtime> Application<RT> {
21932196
Ok(storage_id)
21942197
}
21952198

2199+
pub async fn store_file_entry(
2200+
&self,
2201+
entry: FileStorageEntry,
2202+
) -> anyhow::Result<DeveloperDocumentId> {
2203+
let storage_id = self
2204+
.file_storage
2205+
.store_entry(entry, &self.usage_tracking)
2206+
.await?;
2207+
Ok(storage_id)
2208+
}
2209+
21962210
pub async fn get_file(&self, storage_id: FileStorageId) -> anyhow::Result<FileStream> {
21972211
let mut file_storage_tx = self.begin(Identity::system()).await?;
21982212

@@ -2576,6 +2590,10 @@ impl<RT: Runtime> Application<RT> {
25762590
.map(|(ts, t, _)| (ts, t))
25772591
}
25782592

2593+
pub fn files_storage(&self) -> Arc<dyn Storage> {
2594+
self.files_storage.clone()
2595+
}
2596+
25792597
pub async fn shutdown(&self) -> anyhow::Result<()> {
25802598
self.log_sender.shutdown()?;
25812599
self.table_summary_worker.shutdown().await?;

crates/file_storage/src/core.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,19 @@ impl<RT: Runtime> FileStorage<RT> {
370370
.transactional_file_storage
371371
.upload_file(content_length, content_type, file, expected_sha256)
372372
.await?;
373-
let size = entry.size;
373+
self.store_entry(entry, usage_tracker).await
374+
}
374375

376+
/// Record the existence of a file that has already been uploaded to the
377+
/// underlying storage implementation.
378+
pub async fn store_entry(
379+
&self,
380+
entry: FileStorageEntry,
381+
usage_tracker: &dyn StorageUsageTracker,
382+
) -> anyhow::Result<DeveloperDocumentId> {
375383
// Start/Complete transaction after the slow upload process
376384
// to avoid OCC risk.
385+
let size = entry.size;
377386
let mut tx = self.database.begin(Identity::system()).await?;
378387
let virtual_id = self
379388
.transactional_file_storage

0 commit comments

Comments
 (0)