...
This commit is contained in:
parent
b9df692a54
commit
1f155d1bfb
@ -64,6 +64,10 @@ impl Collection {
|
|||||||
println!("DEBUG: Deleting existing collection data from Redis key 'collections:{}'", self.name);
|
println!("DEBUG: Deleting existing collection data from Redis key 'collections:{}'", self.name);
|
||||||
self.storage.delete_collection(&self.name)?;
|
self.storage.delete_collection(&self.name)?;
|
||||||
|
|
||||||
|
// Store the collection's path in Redis
|
||||||
|
println!("DEBUG: Storing collection path in Redis key 'collections:{}:path'", self.name);
|
||||||
|
self.storage.store_collection_path(&self.name, &self.path.to_string_lossy())?;
|
||||||
|
|
||||||
// Walk through the directory
|
// Walk through the directory
|
||||||
let walker = WalkDir::new(&self.path);
|
let walker = WalkDir::new(&self.path);
|
||||||
for entry_result in walker {
|
for entry_result in walker {
|
||||||
|
@ -207,9 +207,21 @@ impl DocTree {
|
|||||||
return Err(DocTreeError::CollectionNotFound(name.to_string()));
|
return Err(DocTreeError::CollectionNotFound(name.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to get the collection's path from Redis
|
||||||
|
let path = match self.storage.get_collection_path(name) {
|
||||||
|
Ok(path_str) => {
|
||||||
|
println!("DEBUG: Found collection path in Redis: {}", path_str);
|
||||||
|
PathBuf::from(path_str)
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("DEBUG: Could not retrieve collection path from Redis: {}", e);
|
||||||
|
PathBuf::new() // Fallback to empty path if not found
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Create a new collection
|
// Create a new collection
|
||||||
let collection = Collection {
|
let collection = Collection {
|
||||||
path: PathBuf::new(), // We don't have the path, but it's not needed for Redis operations
|
path,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
storage: self.storage.clone(),
|
storage: self.storage.clone(),
|
||||||
};
|
};
|
||||||
@ -236,9 +248,21 @@ impl DocTree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to get the collection's path from Redis
|
||||||
|
let path = match self.storage.get_collection_path(&name) {
|
||||||
|
Ok(path_str) => {
|
||||||
|
println!("DEBUG: Found collection path in Redis: {}", path_str);
|
||||||
|
PathBuf::from(path_str)
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("DEBUG: Could not retrieve collection path from Redis: {}", e);
|
||||||
|
PathBuf::new() // Fallback to empty path if not found
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Create a new collection
|
// Create a new collection
|
||||||
let collection = Collection {
|
let collection = Collection {
|
||||||
path: PathBuf::new(), // We don't have the path, but it's not needed for Redis operations
|
path,
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
storage: self.storage.clone(),
|
storage: self.storage.clone(),
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
//! and processing includes between documents.
|
//! and processing includes between documents.
|
||||||
|
|
||||||
// Import lazy_static for global state
|
// Import lazy_static for global state
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use redis::{Client, Commands, Connection};
|
use redis::{Client, Connection};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use crate::error::{DocTreeError, Result};
|
use crate::error::{DocTreeError, Result};
|
||||||
|
|
||||||
@ -298,6 +298,71 @@ impl RedisStorage {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
/// Store a collection's path
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `collection` - Collection name
|
||||||
|
/// * `path` - Collection path
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// Ok(()) on success or an error
|
||||||
|
pub fn store_collection_path(&self, collection: &str, path: &str) -> Result<()> {
|
||||||
|
let redis_key = format!("collections:{}:path", collection);
|
||||||
|
println!("DEBUG: Redis operation - SET {} {}", redis_key, path);
|
||||||
|
|
||||||
|
// Get a connection from the pool
|
||||||
|
let mut conn = self.connection.lock().unwrap();
|
||||||
|
|
||||||
|
// Store the path using SET
|
||||||
|
redis::cmd("SET")
|
||||||
|
.arg(&redis_key)
|
||||||
|
.arg(path)
|
||||||
|
.execute(&mut *conn);
|
||||||
|
|
||||||
|
println!("DEBUG: Stored collection path in Redis - collection: '{}', path: '{}'",
|
||||||
|
collection, path);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a collection's path
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `collection` - Collection name
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// The collection path or an error
|
||||||
|
pub fn get_collection_path(&self, collection: &str) -> Result<String> {
|
||||||
|
let redis_key = format!("collections:{}:path", collection);
|
||||||
|
println!("DEBUG: Redis operation - GET {}", redis_key);
|
||||||
|
|
||||||
|
// Get a connection from the pool
|
||||||
|
let mut conn = self.connection.lock().unwrap();
|
||||||
|
|
||||||
|
// Get the path using GET
|
||||||
|
let result: Option<String> = redis::cmd("GET")
|
||||||
|
.arg(&redis_key)
|
||||||
|
.query(&mut *conn)
|
||||||
|
.map_err(|e| DocTreeError::RedisError(format!("Redis error: {}", e)))?;
|
||||||
|
|
||||||
|
// Check if the path exists
|
||||||
|
match result {
|
||||||
|
Some(path) => {
|
||||||
|
println!("DEBUG: Retrieved collection path from Redis - collection: '{}', path: '{}'",
|
||||||
|
collection, path);
|
||||||
|
Ok(path)
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
println!("DEBUG: Collection path not found in Redis - collection: '{}'",
|
||||||
|
collection);
|
||||||
|
Err(DocTreeError::CollectionNotFound(collection.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement Clone for RedisStorage
|
// Implement Clone for RedisStorage
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use pulldown_cmark::{Parser, Options, html};
|
use pulldown_cmark::{Parser, Options, html};
|
||||||
use std::path::Path;
|
|
||||||
use sal::text;
|
use sal::text;
|
||||||
|
|
||||||
/// Fix a name to be used as a key
|
/// Fix a name to be used as a key
|
||||||
|
Loading…
Reference in New Issue
Block a user