From b030b1eeb7fb732bf0520a12c95998faeffed07d Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 23 Nov 2024 11:14:03 +0100 Subject: [PATCH] fixing user posts not being displayed --- depell/src/main.rs | 25 +++++++++++++++++++++++-- depell/wasm-hbc/src/lib.rs | 12 ++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/depell/src/main.rs b/depell/src/main.rs index 587cd0ac..7de08ccd 100644 --- a/depell/src/main.rs +++ b/depell/src/main.rs @@ -786,8 +786,29 @@ mod db { login: "INSERT OR REPLACE INTO session (id, username, expiration) VALUES(?, ?, ?)", logout: "DELETE FROM session WHERE id = ?", 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_user_posts: "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, ( + 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(*) FROM roots + JOIN run ON roots.name = run.code_name + AND roots.author = run.code_author + ) AS runs FROM post as outher WHERE author = ? ORDER BY timestamp DESC", // TODO: we might want to cache the recursive queries get_pots_before: "SELECT author, name, timestamp, code, ( WITH RECURSIVE roots(name, author, code) AS ( diff --git a/depell/wasm-hbc/src/lib.rs b/depell/wasm-hbc/src/lib.rs index 8800b8f6..ba2edda0 100644 --- a/depell/wasm-hbc/src/lib.rs +++ b/depell/wasm-hbc/src/lib.rs @@ -4,6 +4,7 @@ use { alloc::{string::String, vec::Vec}, + core::ffi::CStr, hblang::{ son::{hbvm::HbvmBackend, Codegen, CodegenCtx}, ty::Module, @@ -98,8 +99,15 @@ unsafe fn compile_and_run(mut fuel: usize) { break; } Ok(hbvm::VmRunOk::Ecall) => { - let unknown = ct.vm.read_reg(2).0; - log::error!("unknown ecall: {unknown}") + let kind = ct.vm.read_reg(2).0; + match kind { + 0 => { + let str = ct.vm.read_reg(3).0; + let str = unsafe { CStr::from_ptr(str as _) }; + log::error!("{}", str.to_str().unwrap()); + } + unknown => log::error!("unknown ecall: {unknown}"), + } } Ok(hbvm::VmRunOk::Timer) => { fuel -= 1;