From 3c5a8ad529a138390129e7abcc271292ec0f3345 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 22 Aug 2024 16:21:47 +0100 Subject: [PATCH] WIP --- src/lib.rs | 3 --- src/schema_cache.rs | 41 ----------------------------------------- 2 files changed, 44 deletions(-) delete mode 100644 src/schema_cache.rs diff --git a/src/lib.rs b/src/lib.rs index e6acc328b..eb486da66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ mod errors; mod input; mod lookup_key; mod recursion_guard; -mod schema_cache; mod serializers; mod tools; mod url; @@ -134,7 +133,5 @@ fn _pydantic_core(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(to_jsonable_python, m)?)?; m.add_function(wrap_pyfunction!(list_all_errors, m)?)?; m.add_function(wrap_pyfunction!(validate_core_schema, m)?)?; - m.add_function(wrap_pyfunction!(schema_cache::cache_built_schema, m)?)?; - m.add_function(wrap_pyfunction!(schema_cache::retrieve_schema, m)?)?; Ok(()) } diff --git a/src/schema_cache.rs b/src/schema_cache.rs deleted file mode 100644 index 9d1ece160..000000000 --- a/src/schema_cache.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::sync::OnceLock; - -use pyo3::{ - types::{PyAnyMethods, PyDict}, - Bound, Py, PyAny, Python, -}; - -/// Intended to be a `WeakKeyDictionary[Type, CoreSchema]` -static CORE_SCHEMA_CACHE: OnceLock> = OnceLock::new(); - -fn get_cache(py: Python<'_>) -> Bound<'_, PyDict> { - let dict = CORE_SCHEMA_CACHE - .get_or_init(|| { - py.eval_bound( - " - import weakref - weakref.WeakKeyDictionary() - ", - None, - None, - ) - .unwrap() - .unbind() - }) - .downcast_bound::(py) - .unwrap(); - - dict.clone() -} - -#[pyo3::pyfunction] -pub fn cache_built_schema(py: Python<'_>, ty: Py, schema: Py) { - let cache = get_cache(py); - cache.set_item(ty, schema).unwrap(); -} - -#[pyo3::pyfunction] -pub fn retrieve_schema(py: Python<'_>, ty: Py) -> Py { - let cache = get_cache(py); - cache.get_item(ty).unwrap().into() -}