check to see if the cache is empty before enabling GC. More logging

This commit is contained in:
Jack Wright 2024-07-02 11:53:59 -07:00
parent 0d060aeae8
commit 0ec8dd8472
2 changed files with 9 additions and 4 deletions

View File

@ -69,10 +69,12 @@ impl Cache {
None
};
// Once there are no more entries in the cache
// we can turn plugin gc back on
debug!("PolarsPlugin: Cache is empty enabling GC");
engine.set_gc_disabled(false).map_err(LabeledError::from)?;
if lock.is_empty() {
// Once there are no more entries in the cache
// we can turn plugin gc back on
debug!("PolarsPlugin: Cache is empty enabling GC");
engine.set_gc_disabled(false).map_err(LabeledError::from)?;
}
drop(lock);
Ok(removed)
}

View File

@ -3,6 +3,7 @@ use std::cmp::Ordering;
use cache::cache_commands;
pub use cache::{Cache, Cacheable};
use dataframe::{stub::PolarsCmd, values::CustomValueType};
use log::debug;
use nu_plugin::{EngineInterface, Plugin, PluginCommand};
mod cache;
@ -41,6 +42,7 @@ impl EngineWrapper for &EngineInterface {
}
fn set_gc_disabled(&self, disabled: bool) -> Result<(), ShellError> {
debug!("set_gc_disabled called with {disabled}");
EngineInterface::set_gc_disabled(self, disabled)
}
}
@ -72,6 +74,7 @@ impl Plugin for PolarsPlugin {
engine: &EngineInterface,
custom_value: Box<dyn CustomValue>,
) -> Result<(), LabeledError> {
debug!("custom_value_dropped called {:?}", custom_value);
if !self.disable_cache_drop {
let id = CustomValueType::try_from_custom_value(custom_value)?.id();
let _ = self.cache.remove(engine, &id, false);