Skip to content

Commit

Permalink
internal: use gz to compress historical json data
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Nov 29, 2024
1 parent ab2c863 commit d7ef40a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add ./webapp/public/data.jsonl
git add ./webapp/public/*.gz
git add ./repos.txt
git commit -m "Update data.jsonl" || echo "No changes to commit"
git commit -m "Update data" || echo "No changes to commit"
- name: Push changes
run: git push
Expand All @@ -77,7 +77,7 @@ jobs:
run: |
pnpm run build
sed -i '' 's|="/assets|="/moon-build-dashboard/assets|g' ./dist/index.html
sed -i '' 's|"/data.jsonl"|"/moon-build-dashboard/data.jsonl"|g' ./dist/assets/*.js
sed -i '' 's|"/latest_data.jsonl.gz"|"/moon-build-dashboard/latest_data.jsonl.gz"|g' ./dist/assets/*.js
working-directory: ./webapp

- name: Deploy to GitHub Pages
Expand Down
26 changes: 15 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,25 +437,22 @@ fn main0() -> anyhow::Result<()> {
};
match res {
Ok(dashboard) => {
let fp = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open("webapp/public/data.jsonl")?;
let mut writer = std::io::BufWriter::new(fp);
writeln!(writer, "{}", serde_json::to_string(&dashboard)?)?;
writer.flush()?;
let date = Local::now().format("%Y-%m-%d");
let filename = format!("webapp/public/{}_data.jsonl.gz", date);

let fp = std::fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true) // make sure to truncate the file
.open("webapp/public/latest_data.jsonl.gz")?;

// create a gzip encoder
.truncate(true)
.open(&filename)?;
let encoder = GzEncoder::new(fp, Compression::default());
let mut writer = std::io::BufWriter::new(encoder);
writeln!(writer, "{}", serde_json::to_string(&dashboard)?)?;
writer.flush()?;

let latest_filename = "webapp/public/latest_data.jsonl.gz";
std::fs::copy(&filename, latest_filename)?;

Ok(())
}
Err(e) => Err(anyhow::anyhow!(e)),
Expand All @@ -465,3 +462,10 @@ fn main0() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
main0()
}

#[test]
fn test_main() {
use chrono::Local;
let date = Local::now().format("%Y-%m-%d");
println!("{}", date);
}

0 comments on commit d7ef40a

Please sign in to comment.