pub fn update<F>(&self, ids: Vec<&str>, action: F)
    where F: FnOnce(Vec<Option<Post>>) -> Vec<Option<Post>> {
        let posts = self.read(ids);
        let posts = action(posts);
        let mut handles: Vec<std::thread::JoinHandle<()>> = vec![];
        for maybe_post in posts {
            if let Some(mut post) = maybe_post {
                if post.human_readable_url == "" {
                    post.human_readable_url = to_url_part(&post.content);
                }
                if post.access_hash != "" {
                    self.at(&["access_hash", &post.access_hash]).ok().map(|node| {
                        // To not overwrite, this needs a `".validate": "!data.exists()"` rule on `"access_hash"/"$hash"`.
                        let b = to_string(&UserFirstPost{
                            first_post_id: post.id.clone(),
                        }).ok();
                        b.map(|body| handles.push(node.update_async(body, |_| ())));
                    });
                }
                self.at(&["human_readable_url", &post.human_readable_url]).ok().map(|node| {
                    let b = to_string(&Shortened {
                        post_id: post.id.clone(),
                    }).ok();
                    b.map(|body| handles.push(node.update_async(body, |_| ())));
                });
                self.at(&["posts", &post.id]).ok().map(|node| {
                    let b = to_string(&post).ok();
                    b.map(|body| handles.push(node.set_async(body, |_| ())));
                });
            }
        }
        for handle in handles { handle.join().unwrap(); }
    }
/// Updates many posts in the database at once: read, process, write, as one "atomic" operation.
/// 
/// (Well, "atomic" is a word too strong for this: it was a nice thought, but firebase-rs has never heard of atomicity, and we don't care enough to implement transactions ourselves (https://stackoverflow.com/questions/23041800/firebase-transactions-via-rest-api).)
/// (It first reads all, then writes all, each of these being atomic.)
/// (And, `posts_api` reads/updates `children`, `rewarded_posts`, `created_post_ids` directly, with no regard for atomicity.)
Updates many posts in the database at once: read, process, write, as one "atomic" operation.
Updates many posts in the database at once : read process write as one " atomic " operation .
pub fn update<F>(&self, ids: Vec<&str>, action: F)
    where F: FnOnce(Vec<Option<Post>>) -> Vec<Option<Post>> {
        let posts = self.read(ids);
        let posts = action(posts);
        let mut handles: Vec<std::thread::JoinHandle<()>> = vec![];
        for maybe_post in posts {
            if let Some(mut post) = maybe_post {
                if post.human_readable_url == "" {
                    post.human_readable_url = to_url_part(&post.content);
                }
                if post.access_hash != "" {
                    self.at(&["access_hash", &post.access_hash]).ok().map(|node| {
                        // To not overwrite, this needs a `".validate": "!data.exists()"` rule on `"access_hash"/"$hash"`.
                        let b = to_string(&UserFirstPost{
                            first_post_id: post.id.clone(),
                        }).ok();
                        b.map(|body| handles.push(node.update_async(body, |_| ())));
                    });
                }
                self.at(&["human_readable_url", &post.human_readable_url]).ok().map(|node| {
                    let b = to_string(&Shortened {
                        post_id: post.id.clone(),
                    }).ok();
                    b.map(|body| handles.push(node.update_async(body, |_| ())));
                });
                self.at(&["posts", &post.id]).ok().map(|node| {
                    let b = to_string(&post).ok();
                    b.map(|body| handles.push(node.set_async(body, |_| ())));
                });
            }
        }
        for handle in handles { handle.join().unwrap(); }
    }
pub fn update < F > ( & self , ids : Vec < & str > , action : F ) where F : FnOnce ( Vec < Option < Post > > ) -> Vec < Option < Post > > { let posts = self . read ( ids ) ; let posts = action ( posts ) ; let mut handles : Vec < std :: thread :: JoinHandle < ( ) > > = vec ! [ ] ; for maybe_post in posts { if let Some ( mut post ) = maybe_post { if post . human_readable_url == " " { post . human_readable_url = to_url_part ( & post . content ) ; } if post . access_hash != " " { self . at ( & [ " " , & post . access_hash ] ) . ok ( ) . map ( | node | { // To not overwrite, this needs a `".validate": "!data.exists()"` rule on `"access_hash"/"$hash"`. let b = to_string ( & UserFirstPost { first_post_id : post . id . clone ( ) , } ) . ok ( ) ; b . map ( | body | handles . push ( node . update_async ( body , | _ | ( ) ) ) ) ; } ) ; } self . at ( & [ " " , & post . human_readable_url ] ) . ok ( ) . map ( | node | { let b = to_string ( & Shortened { post_id : post . id . clone ( ) , } ) . ok ( ) ; b . map ( | body | handles . push ( node . update_async ( body , | _ | ( ) ) ) ) ; } ) ; self . at ( & [ " " , & post . id ] ) . ok ( ) . map ( | node | { let b = to_string ( & post ) . ok ( ) ; b . map ( | body | handles . push ( node . set_async ( body , | _ | ( ) ) ) ) ; } ) ; } } for handle in handles { handle . join ( ) . unwrap ( ) ; } }
Updates many posts in the database at once: read, process, write, as one "atomic" operation.
Updates many posts in the database at once : read process write as one " atomic " operation .
&self
ids
Vec<&str>
action
F
&self
ids
Vec<&str>
action
F