@@ -24,6 +24,7 @@ use std::{
2424use arrow_schema:: Schema ;
2525use bytes:: Bytes ;
2626use chrono:: { DateTime , Utc } ;
27+ use dashmap:: DashMap ;
2728use http:: StatusCode ;
2829use relative_path:: RelativePathBuf ;
2930use tonic:: async_trait;
@@ -188,6 +189,54 @@ impl Metastore for ObjectStoreMetastore {
188189 . await ?)
189190 }
190191
192+ /// Fetch all chats
193+ async fn get_chats ( & self ) -> Result < DashMap < String , Vec < Bytes > > , MetastoreError > {
194+ let all_user_chats = DashMap :: new ( ) ;
195+
196+ let users_dir = RelativePathBuf :: from ( USERS_ROOT_DIR ) ;
197+ for user in self . storage . list_dirs_relative ( & users_dir) . await ? {
198+ if user. starts_with ( "." ) {
199+ continue ;
200+ }
201+ let mut chats = Vec :: new ( ) ;
202+ let chats_path = users_dir. join ( & user) . join ( "chats" ) ;
203+ let user_chats = self
204+ . storage
205+ . get_objects (
206+ Some ( & chats_path) ,
207+ Box :: new ( |file_name| file_name. ends_with ( ".json" ) ) ,
208+ )
209+ . await ?;
210+ for chat in user_chats {
211+ chats. push ( chat) ;
212+ }
213+
214+ all_user_chats. insert ( user, chats) ;
215+ }
216+
217+ Ok ( all_user_chats)
218+ }
219+
220+ /// Save a chat
221+ async fn put_chat ( & self , obj : & dyn MetastoreObject ) -> Result < ( ) , MetastoreError > {
222+ // we need the path to store in obj store
223+ let path = obj. get_object_path ( ) ;
224+
225+ Ok ( self
226+ . storage
227+ . put_object ( & RelativePathBuf :: from ( path) , to_bytes ( obj) )
228+ . await ?)
229+ }
230+
231+ /// Delete a chat
232+ async fn delete_chat ( & self , obj : & dyn MetastoreObject ) -> Result < ( ) , MetastoreError > {
233+ let path = obj. get_object_path ( ) ;
234+ Ok ( self
235+ . storage
236+ . delete_object ( & RelativePathBuf :: from ( path) )
237+ . await ?)
238+ }
239+
191240 // for get filters, take care of migration and removal of incorrect/old filters
192241 // return deserialized filter
193242 async fn get_filters ( & self ) -> Result < Vec < Filter > , MetastoreError > {
0 commit comments