From fb2a7c3ba1b985c03d969d5d89c0e1fc3012a65e Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 22 Aug 2025 07:44:09 +0000 Subject: [PATCH] all --- backend/windmill-api/src/scripts.rs | 12 ++++++-- backend/windmill-common/src/cache.rs | 42 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index de2533a954..f3b3d659ec 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -1389,13 +1389,19 @@ async fn get_empty_ts_script_by_path() -> String { return String::new(); } +#[derive(Deserialize)] +struct RawScriptByPathQuery { + cache_key: Option, +} + async fn raw_script_by_path( authed: ApiAuthed, Extension(user_db): Extension, Extension(db): Extension, Path((w_id, path)): Path<(String, StripPath)>, + Query(query): Query, ) -> Result { - raw_script_by_path_internal(path, user_db, db, authed, w_id, false).await + raw_script_by_path_internal(path, user_db, db, authed, w_id, false, query.cache_key).await } async fn raw_script_by_path_unpinned( @@ -1403,8 +1409,9 @@ async fn raw_script_by_path_unpinned( Extension(user_db): Extension, Extension(db): Extension, Path((w_id, path)): Path<(String, StripPath)>, + Query(query): Query, ) -> Result { - raw_script_by_path_internal(path, user_db, db, authed, w_id, true).await + raw_script_by_path_internal(path, user_db, db, authed, w_id, true, query.cache_key).await } lazy_static::lazy_static! { @@ -1419,6 +1426,7 @@ async fn raw_script_by_path_internal( authed: ApiAuthed, w_id: String, unpin: bool, + cache_key: Option, ) -> Result { let path = path.to_path(); check_scopes(&authed, || format!("scripts:read:{}", path))?; diff --git a/backend/windmill-common/src/cache.rs b/backend/windmill-common/src/cache.rs index 4129948268..925c223887 100644 --- a/backend/windmill-common/src/cache.rs +++ b/backend/windmill-common/src/cache.rs @@ -537,6 +537,48 @@ pub mod flow { } } +pub mod python_import_by_path { + use super::*; + use crate::DB; + + #[derive(Eq, PartialEq, Debug, Hash, Clone)] + pub struct ScriptPathWithCacheKey { + pub path: String, + pub cache_key: String, + } + + impl Item for ScriptPathWithCacheKey { + fn path(&self, root: impl AsRef) -> PathBuf { + root.as_ref() + .join(self.path.clone()) + .join(self.cache_key.clone()) + } + } + + #[derive(Eq, PartialEq, Debug, Hash, Clone, Serialize, Deserialize)] + pub struct ScriptContentOrPrefix { + pub content: String, + pub prefix: bool, + } + + make_static! { + static ref CACHE: { ScriptPathWithCacheKey => ScriptContentOrPrefix } in "python_import_by_path" <= 1000; + } + + pub async fn fetch( + db: &DB, + path: &str, + w_id: &str, + cache_key: &str, + ) -> error::Result { + let r =sqlx::query_scalar!( + "SELECT content FROM script WHERE path = $1 AND workspace_id = $2 AND archived = false ORDER BY created_at DESC LIMIT 1", + path, + w_id + ).fetch_optional(db).await?; + todo!() + } +} pub mod script { use crate::{worker::Connection, DB};