From b12579ff65122952618844d005026eef2cb39e12 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 23 Nov 2024 00:06:25 +0100 Subject: [PATCH] adding import count to posts --- depell/src/icons/download.svg | 1 + depell/src/index.css | 5 +++-- depell/src/main.rs | 35 ++++++++++++++++++++++++++++++----- depell/src/migrations/1.sql | 1 + lang/src/son/hbvm/regalloc.rs | 6 +----- 5 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 depell/src/icons/download.svg create mode 100644 depell/src/migrations/1.sql diff --git a/depell/src/icons/download.svg b/depell/src/icons/download.svg new file mode 100644 index 0000000..ddb30c3 --- /dev/null +++ b/depell/src/icons/download.svg @@ -0,0 +1 @@ + diff --git a/depell/src/index.css b/depell/src/index.css index 5bf4224..1e35f18 100644 --- a/depell/src/index.css +++ b/depell/src/index.css @@ -44,10 +44,11 @@ div.preview { } } - div.stats { + div.stat { display: flex; - gap: var(--small-gap); } + + margin: var(--small-gap) 0px; } form { diff --git a/depell/src/main.rs b/depell/src/main.rs index 27093ea..cfa7192 100644 --- a/depell/src/main.rs +++ b/depell/src/main.rs @@ -253,6 +253,7 @@ impl Post { name: r.get(1)?, timestamp: r.get(2)?, code: r.get(3)?, + imports: r.get(4)?, ..Default::default() }) } @@ -322,13 +323,12 @@ impl fmt::Display for Post { name timestamp - -
- for (name, count) in "inps runs deps".split(' ') + for (name, count) in [include_str!("icons/download.svg"), "runs", "deps"] + .iter() .zip([imports, runs, dependencies]) .filter(|(_, &c)| c != 0) { - name ": "count +
!name count
}
code
@@ -759,7 +759,18 @@ mod db { get_session: "SELECT username, expiration FROM session WHERE id = ?", get_user_posts: "SELECT author, name, timestamp, code FROM post WHERE author = ? ORDER BY timestamp DESC", - get_pots_before: "SELECT author, name, timestamp, code FROM post WHERE timestamp < ?", + // TODO: we might want to cache the recursive queries + get_pots_before: "SELECT author, name, timestamp, code, ( + WITH RECURSIVE roots(name, author, code) AS ( + SELECT name, author, code FROM post WHERE name = outher.name AND author = outher.author + UNION + SELECT post.name, post.author, post.code FROM + post JOIN import ON post.name = import.from_name + AND post.author = import.from_author + JOIN roots ON import.to_name = roots.name + AND import.to_author = roots.author + ) SELECT (count(*) - 1) FROM roots + ) AS imports FROM post AS outher WHERE timestamp < ?", create_post: "INSERT INTO post (name, author, timestamp, code) VALUES(?, ?, ?, ?)", fetch_deps: " WITH RECURSIVE roots(name, author, code) AS ( @@ -800,8 +811,22 @@ mod db { } pub fn init() { + const SCHEMA_VERSION: usize = 0; + const MIGRATIONS: &[&str] = &[include_str!("migrations/1.sql")]; + let db = rusqlite::Connection::open("db.sqlite").unwrap(); db.execute_batch(include_str!("schema.sql")).unwrap(); + + let schema_version = + db.pragma_query_value(None, "user_version", |v| v.get::<_, usize>(0)).unwrap(); + + if schema_version != SCHEMA_VERSION { + for &mig in &MIGRATIONS[schema_version..] { + db.execute_batch(mig).expect(mig); + } + db.pragma_update(None, "user_version", SCHEMA_VERSION).unwrap(); + } + Queries::new(&db); } } diff --git a/depell/src/migrations/1.sql b/depell/src/migrations/1.sql new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/depell/src/migrations/1.sql @@ -0,0 +1 @@ + diff --git a/lang/src/son/hbvm/regalloc.rs b/lang/src/son/hbvm/regalloc.rs index c3551db..eac2e3a 100644 --- a/lang/src/son/hbvm/regalloc.rs +++ b/lang/src/son/hbvm/regalloc.rs @@ -9,11 +9,7 @@ use { PLoc, Sig, Types, }, alloc::{borrow::ToOwned, vec::Vec}, - core::{ - mem, - ops::{Range, RangeBounds}, - usize, - }, + core::{mem, ops::Range}, hbbytecode::{self as instrs}, };