From b9c0e7cd550ab14fa7da7e33ed87cbeeeb9785a0 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 1 Jul 2023 23:52:30 +0100 Subject: Reland "fix(cli): don't store blob and data urls in the module cache" (#18581) Relands #18261 now that https://github.com/lucacasonato/esbuild_deno_loader/pull/54 is landed and used by fresh. Fixes #18260. --- ext/web/blob.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'ext/web/blob.rs') diff --git a/ext/web/blob.rs b/ext/web/blob.rs index 9c5f5a09c..3481f6178 100644 --- a/ext/web/blob.rs +++ b/ext/web/blob.rs @@ -23,10 +23,10 @@ use crate::Location; pub type PartMap = HashMap>; -#[derive(Clone, Default, Debug)] +#[derive(Default, Debug)] pub struct BlobStore { - parts: Arc>, - object_urls: Arc>>>, + parts: Mutex, + object_urls: Mutex>>, } impl BlobStore { @@ -80,6 +80,11 @@ impl BlobStore { let mut blob_store = self.object_urls.lock(); blob_store.remove(url); } + + pub fn clear(&self) { + self.parts.lock().clear(); + self.object_urls.lock().clear(); + } } #[derive(Debug)] @@ -162,7 +167,7 @@ impl BlobPart for SlicedBlobPart { #[op] pub fn op_blob_create_part(state: &mut OpState, data: JsBuffer) -> Uuid { - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); let part = InMemoryBlobPart(data.to_vec()); blob_store.insert_part(Arc::new(part)) } @@ -180,7 +185,7 @@ pub fn op_blob_slice_part( id: Uuid, options: SliceOptions, ) -> Result { - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); let part = blob_store .get_part(&id) .ok_or_else(|| type_error("Blob part not found"))?; @@ -207,7 +212,7 @@ pub async fn op_blob_read_part( ) -> Result { let part = { let state = state.borrow(); - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); blob_store.get_part(&id) } .ok_or_else(|| type_error("Blob part not found"))?; @@ -217,7 +222,7 @@ pub async fn op_blob_read_part( #[op] pub fn op_blob_remove_part(state: &mut OpState, id: Uuid) { - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); blob_store.remove_part(&id); } @@ -228,7 +233,7 @@ pub fn op_blob_create_object_url( part_ids: Vec, ) -> Result { let mut parts = Vec::with_capacity(part_ids.len()); - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); for part_id in part_ids { let part = blob_store .get_part(&part_id) @@ -239,7 +244,7 @@ pub fn op_blob_create_object_url( let blob = Blob { media_type, parts }; let maybe_location = state.try_borrow::(); - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); let url = blob_store .insert_object_url(blob, maybe_location.map(|location| location.0.clone())); @@ -253,7 +258,7 @@ pub fn op_blob_revoke_object_url( url: &str, ) -> Result<(), AnyError> { let url = Url::parse(url)?; - let blob_store = state.borrow::(); + let blob_store = state.borrow::>(); blob_store.remove_object_url(&url); Ok(()) } @@ -280,7 +285,7 @@ pub fn op_blob_from_object_url( return Ok(None); } - let blob_store = state.try_borrow::().ok_or_else(|| { + let blob_store = state.try_borrow::>().ok_or_else(|| { type_error("Blob URLs are not supported in this context.") })?; if let Some(blob) = blob_store.get_object_url(url) { -- cgit v1.2.3