Skip to content

Commit

Permalink
Merge pull request #88 from proshunsuke/v3.0.3
Browse files Browse the repository at this point in the history
v3.0.3
  • Loading branch information
proshunsuke authored Dec 28, 2022
2 parents 904f8a4 + ab0b6ae commit 98ef9ed
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Packaging

# v3.0.3

https://github.com/proshunsuke/colmsg/pull/88

## Fix

* Use [rayon](https://crates.io/crates/rayon) to speed up internal processing

# v3.0.2

https://github.com/proshunsuke/colmsg/pull/86
Expand Down
83 changes: 82 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "colmsg"
version = "3.0.2"
version = "3.0.3"
authors = ["proshunsuke <[email protected]>"]
categories = ["command-line-utilities"]
description="Save the messages of '櫻坂46メッセージ', '日向坂46メッセージ' and '乃木坂46メッセージ' apps to the local."
Expand All @@ -25,6 +25,7 @@ shell-words = "^0.1.0"
chrono = "^0.4.10"
serde_json = "^1.0.0"
walkdir = "^2.3.1"
rayon = "^1.6.1"
regex = "^1.3.5"
url = "^2.1.1"

Expand Down
10 changes: 8 additions & 2 deletions src/message/saver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;
use std::path::{PathBuf};

use rayon::prelude::*;
use regex::Regex;
use walkdir::{WalkDir, DirEntry};
use chrono::NaiveDateTime;
Expand All @@ -11,6 +12,10 @@ use crate::{
message::file::{Text, Picture, SaveToFile, Video, Voice},
};

lazy_static! {
static ref ID_DATE_REGEX: Regex = Regex::new(r"(?x)(?P<id>\d+)_\d_(?P<date>\d+)").unwrap();
}

pub struct Saver<'a, C: SHNClient> {
config: &'a Config<'a, C>,
}
Expand Down Expand Up @@ -46,7 +51,7 @@ impl<'b, C: SHNClient> Saver<'b, C> {
}

fn create_member_identifier_list(&self, group: &Vec<Groups>, tags: &Vec<Tags>) -> Vec<MemberIdentifier> {
let mut member_identifier_vec = Vec::new();
let mut member_identifier_vec = Vec::with_capacity(group.len());
group.iter().for_each(|g| { // もっといい書き方があるはず
let mut group = "".to_string();
let mut gen = "".to_string();
Expand Down Expand Up @@ -175,6 +180,7 @@ impl<'b, C: SHNClient> Saver<'b, C> {
fn id_dates(&self, dir_buf: &PathBuf) -> Vec<IdDate> {
let mut result = WalkDir::new(dir_buf)
.into_iter()
.par_bridge()
.filter(|r| !r.as_ref().unwrap().path().is_dir())
.map(|r| {
let dir_entry = r.unwrap();
Expand Down Expand Up @@ -215,7 +221,7 @@ struct IdDate {
}

fn dir_entry_to_id_date(filename: &DirEntry) -> Option<IdDate> {
let re = Regex::new(r"(?x)(?P<id>\d+)_\d_(?P<date>\d+)").unwrap();
let re = ID_DATE_REGEX.clone();
re.captures(filename.file_name().to_str().unwrap())
.and_then(|cap|Some(IdDate {
id: cap["id"].parse::<u32>().unwrap(),
Expand Down

0 comments on commit 98ef9ed

Please sign in to comment.