From e1cb00f0b199f40eaefe74730b37381e55835aac Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Wed, 14 Jan 2026 16:12:15 -0800 Subject: [PATCH 01/32] Basic fetch channel --- koucha/Cargo.lock | 2120 ++++++++++++++++++++++++++++++++++++++ koucha/Cargo.toml | 4 + koucha/src/bin/server.rs | 11 + koucha/src/lib.rs | 21 + 4 files changed, 2156 insertions(+) diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index 476c80f..f4dd308 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -2,6 +2,2126 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "atom_syndication" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f68d23e2cb4fd958c705b91a6b4c80ceeaf27a9e11651272a8389d5ce1a4a3" +dependencies = [ + "chrono", + "derive_builder", + "diligent-date-parser", + "never", + "quick-xml", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "aws-lc-rs" +version = "1.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e84ce723ab67259cfeb9877c6a639ee9eb7a27b28123abd71db7f0d5d0cc9d86" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a442ece363113bd4bd4c8b18977a7798dd4d3c3383f34fb61936960e8f4ad8" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] + +[[package]] +name = "axum" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + +[[package]] +name = "cc" +version = "1.2.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +dependencies = [ + "num-traits", +] + +[[package]] +name = "cmake" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "derive_builder" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" +dependencies = [ + "derive_builder_core", + "syn", +] + +[[package]] +name = "diligent-date-parser" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ede7d79366f419921e2e2f67889c12125726692a313bffb474bd5f37a581e9" +dependencies = [ + "chrono", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "koucha" version = "0.1.0" +dependencies = [ + "axum", + "reqwest", + "rss", + "tokio", +] + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "never" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "openssl-probe" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f50d9b3dabb09ecd771ad0aa242ca6894994c130308ca3d7684634df8037391" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.37.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +dependencies = [ + "encoding_rs", + "memchr", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.17", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.17", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "reqwest" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rss" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2107738f003660f0a91f56fd3e3bd3ab5d918b2ddaf1e1ec2136fb1c46f71bf" +dependencies = [ + "atom_syndication", + "derive_builder", + "never", + "quick-xml", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "aws-lc-rs", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl 2.0.17", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a29fc0408b113f68cf32637857ab740edfafdf460c326cd2afaa2d84cc05dc" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index b58c658..9a6ab17 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -4,3 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] +axum = "0.8.8" +reqwest = "0.13.1" +rss = "2.0.12" +tokio = { version = "1.49.0", features = ["full"] } diff --git a/koucha/src/bin/server.rs b/koucha/src/bin/server.rs index e69de29..d4a8d34 100644 --- a/koucha/src/bin/server.rs +++ b/koucha/src/bin/server.rs @@ -0,0 +1,11 @@ +use std::error::Error; +use reqwest::Client; +use koucha::fetch_channel; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let client = Client::new(); + let _channel = fetch_channel(&client, "https://lorem-rss.herokuapp.com/feed?unit=year").await?; + Ok(()) +} + diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index e69de29..4d4a38b 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -0,0 +1,21 @@ +use std::error::Error; +use reqwest::{ + IntoUrl, + Client, +}; +use rss::Channel as RawChannel; + +pub struct Channel { + pub channel: rss::Channel, +} + +pub async fn fetch_channel( + client: &Client, url: T) -> Result> { + let content = client.get(url) + .send().await? + .bytes().await?; + + let raw_channel = RawChannel::read_from(&content[..])?; + println!("{}", raw_channel.title); + Ok(Channel { channel: raw_channel }) +} From 985f7242678809c466dd0d14c718f6dc27862892 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 15 Jan 2026 15:45:08 -0800 Subject: [PATCH 02/32] Add sqlx --- flake.nix | 2 + koucha/Cargo.lock | 879 +++++++++++++++++++++++++++++++++++++++++++++- koucha/Cargo.toml | 1 + 3 files changed, 875 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index c3fa77f..79e3a0f 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,8 @@ rustc cargo rust-analyzer + + sqlx-cli ]; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index f4dd308..30d8b80 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "atom_syndication" version = "0.12.7" @@ -107,11 +122,29 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bitflags" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] [[package]] name = "bumpalo" @@ -119,6 +152,12 @@ version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.11.0" @@ -183,6 +222,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "core-foundation" version = "0.9.4" @@ -209,6 +263,55 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "darling" version = "0.20.11" @@ -244,6 +347,17 @@ dependencies = [ "syn", ] +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "derive_builder" version = "0.20.2" @@ -275,6 +389,18 @@ dependencies = [ "syn", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + [[package]] name = "diligent-date-parser" version = "0.1.5" @@ -295,12 +421,27 @@ dependencies = [ "syn", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "dunce" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + [[package]] name = "encoding_rs" version = "0.8.35" @@ -323,7 +464,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", ] [[package]] @@ -332,12 +495,29 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -360,6 +540,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -368,6 +549,34 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + [[package]] name = "futures-sink" version = "0.3.31" @@ -387,9 +596,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", + "futures-io", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", ] [[package]] @@ -438,12 +661,71 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "http" version = "1.4.0" @@ -669,7 +951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.16.1", ] [[package]] @@ -743,15 +1025,53 @@ dependencies = [ "axum", "reqwest", "rss", + "sqlx", "tokio", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + [[package]] name = "libc" version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags", + "libc", + "redox_syscall 0.7.0", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "litemap" version = "0.8.1" @@ -785,6 +1105,16 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.6" @@ -814,6 +1144,42 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.5", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -821,6 +1187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -835,6 +1202,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f50d9b3dabb09ecd771ad0aa242ca6894994c130308ca3d7684634df8037391" +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -853,11 +1226,20 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", "windows-link", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.2" @@ -876,6 +1258,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + [[package]] name = "potential_utf" version = "0.1.4" @@ -943,7 +1352,7 @@ dependencies = [ "bytes", "getrandom 0.3.4", "lru-slab", - "rand", + "rand 0.9.2", "ring", "rustc-hash", "rustls", @@ -984,14 +1393,35 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + [[package]] name = "rand" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ - "rand_chacha", - "rand_core", + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", ] [[package]] @@ -1001,7 +1431,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", ] [[package]] @@ -1022,6 +1461,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +dependencies = [ + "bitflags", +] + [[package]] name = "reqwest" version = "0.13.1" @@ -1074,6 +1522,26 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rss" version = "2.0.12" @@ -1292,6 +1760,28 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1308,6 +1798,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + [[package]] name = "slab" version = "0.4.11" @@ -1319,6 +1819,9 @@ name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -1330,12 +1833,230 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror 2.0.17", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand 0.8.5", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.17", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand 0.8.5", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror 2.0.17", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror 2.0.17", + "tracing", + "url", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + [[package]] name = "strsim" version = "0.11.1" @@ -1503,6 +2224,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.18" @@ -1570,9 +2302,21 @@ checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -1588,12 +2332,39 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + [[package]] name = "untrusted" version = "0.9.0" @@ -1618,6 +2389,18 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "walkdir" version = "2.5.0" @@ -1652,6 +2435,12 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.106" @@ -1739,6 +2528,16 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + [[package]] name = "winapi-util" version = "0.1.11" @@ -1792,6 +2591,15 @@ dependencies = [ "windows-targets 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -1834,6 +2642,21 @@ dependencies = [ "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -1873,6 +2696,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -1891,6 +2720,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" @@ -1909,6 +2744,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1939,6 +2780,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" @@ -1957,6 +2804,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" @@ -1975,6 +2828,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" @@ -1993,6 +2852,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index 9a6ab17..4198f3f 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -8,3 +8,4 @@ axum = "0.8.8" reqwest = "0.13.1" rss = "2.0.12" tokio = { version = "1.49.0", features = ["full"] } +sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } From e2153c2eed6f786d3c52237256b69ddf381664fd Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 16 Jan 2026 13:13:02 -0800 Subject: [PATCH 03/32] Sql initial schema --- koucha/.gitignore | 1 + .../20260115003047_initial_schema.sql | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 koucha/migrations/20260115003047_initial_schema.sql diff --git a/koucha/.gitignore b/koucha/.gitignore index ea8c4bf..6dfb7e0 100644 --- a/koucha/.gitignore +++ b/koucha/.gitignore @@ -1 +1,2 @@ +*.db /target diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql new file mode 100644 index 0000000..d489adb --- /dev/null +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -0,0 +1,50 @@ +-- Add migration script here + +PRAGMA foreign_keys = ON; + +CREATE TABLE users ( + id INTEGER PRIMARY KEY, + name TEXT UNIQUE NOT NULL +); + +CREATE TABLE channels ( + id INTEGER PRIMARY KEY, + url TEXT UNIQUE NOT NULL, + last_fetched INTEGER +); + +CREATE TABLE items ( + id INTEGER PRIMARY KEY, + channel_id INTEGER NOT NULL, + guid TEXT NOT NULL, + fetched_at INTEGER NOT NULL, + UNIQUE(channel_id, guid), + FOREIGN KEY (channel_id) REFERENCES channels(id) +); + +CREATE TABLE feeds ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + FOREIGN KEY (user_id) REFERENCES users(id) +); + +CREATE TABLE feed_channels ( + feed_id INTEGER NOT NULL, + channel_id INTEGER NOT NULL, + -- Decay settings will go here + PRIMARY KEY (feed_id, channel_id), + FOREIGN KEY (feed_id) REFERENCES feeds(id), + FOREIGN KEY (channel_id) REFERENCES channels(id) +); + +CREATE TABLE feed_items ( + item_id INTEGER NOT NULL, + feed_id INTEGER NOT NULL, + score INTEGER NOT NULL, + archived BOOLEAN DEFAULT FALSE, + PRIMARY KEY (item_id, feed_id), + FOREIGN KEY (feed_id) REFERENCES feeds(id), + FOREIGN KEY (item_id) REFERENCES items(id) +); +CREATE INDEX idx_feed_items_score +ON feed_items(feed_id, archived, score DESC); From 41badb6c9f9cadcd91f0f32649c9eaf7dacb8c8a Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 16 Jan 2026 13:13:20 -0800 Subject: [PATCH 04/32] Adapter and User --- koucha/src/lib.rs | 94 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 4d4a38b..392e221 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -5,12 +5,104 @@ use reqwest::{ }; use rss::Channel as RawChannel; +type Result = std::result::Result>; + +pub struct AdapterOptions { + database_url: String, +} + +impl AdapterOptions { + pub fn new() -> Self { + Self { + database_url: "sqlite:test.db".to_string(), + } + } + + pub fn database_url(mut self, url: &str) -> Self { + self.database_url = url.to_string(); + self + } + + pub async fn create(self) -> Result { + let db = sqlx::sqlite::SqlitePoolOptions::new() + .connect(&self.database_url).await?; + + Ok(Adapter { db }) + } +} + +pub struct Adapter { + db: sqlx::SqlitePool, +} + +impl Adapter { + pub async fn get_all_users(&self) -> Result> { + let users_query = sqlx::query!("SELECT id, name FROM users") + .fetch_all(&self.db).await?; + + let mut all_users: Vec = Vec::with_capacity(users_query.len()); + + for user in users_query { + all_users.push(User { + id: user.id, + name: user.name, + }) + } + + Ok(all_users) + } + + fn get_pool(&self) -> &sqlx::SqlitePool { &self.db } +} + +pub struct User { + id: i64, + name: String, +} + +impl User { + pub async fn get_by_id(adapter: &Adapter, id: i64) -> Result { + let user = sqlx::query!("SELECT name FROM users WHERE id = ?", id) + .fetch_one(adapter.get_pool()).await?; + + Ok(Self { + id: id, + name: user.name, + }) + } + + pub async fn create(adapter: &Adapter, name: &str) -> Result { + let result = sqlx::query!("INSERT INTO users (name) VALUES (?)", name) + .execute(adapter.get_pool()).await?; + + Ok(Self { + id: result.last_insert_rowid(), + name: name.to_string() + }) + } + + pub async fn change_name( + &mut self, adapter: &Adapter, new_name: &str) -> Result<()> { + sqlx::query!( + "UPDATE users SET name = ? WHERE id = ?", + new_name, self.id + ).execute(adapter.get_pool()).await?; + + self.name = new_name.to_string(); + + Ok(()) + } + + pub fn name(&self) -> &str { &self.name } + pub fn id(&self) -> i64 { self.id } +} + pub struct Channel { pub channel: rss::Channel, } pub async fn fetch_channel( - client: &Client, url: T) -> Result> { + client: &Client, url: T) -> Result { let content = client.get(url) .send().await? .bytes().await?; From f42e558db9d7105ebf0bb1ce5bcdc205ef70be56 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 20 Jan 2026 11:36:26 -0800 Subject: [PATCH 05/32] Added content fields to initial schema --- koucha/migrations/20260115003047_initial_schema.sql | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql index d489adb..d437df3 100644 --- a/koucha/migrations/20260115003047_initial_schema.sql +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -9,15 +9,22 @@ CREATE TABLE users ( CREATE TABLE channels ( id INTEGER PRIMARY KEY, - url TEXT UNIQUE NOT NULL, - last_fetched INTEGER + title TEXT NOT NULL, + link TEXT UNIQUE NOT NULL, + description TEXT, + last_fetched TEXT ); CREATE TABLE items ( id INTEGER PRIMARY KEY, channel_id INTEGER NOT NULL, guid TEXT NOT NULL, - fetched_at INTEGER NOT NULL, + fetched_at TEXT NOT NULL, + + title TEXT, + description TEXT, + content TEXT, + UNIQUE(channel_id, guid), FOREIGN KEY (channel_id) REFERENCES channels(id) ); From 22871f578990b0eca39e8c0e4f3c2f977539d582 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 20 Jan 2026 11:37:00 -0800 Subject: [PATCH 06/32] Fetching data with channels --- koucha/Cargo.lock | 73 ++++++++++++++++++ koucha/Cargo.toml | 1 + koucha/src/lib.rs | 188 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 225 insertions(+), 37 deletions(-) diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index 30d8b80..1fb6b65 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -8,6 +8,15 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "atoi" version = "2.0.0" @@ -200,7 +209,11 @@ version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" dependencies = [ + "iana-time-zone", + "js-sys", "num-traits", + "wasm-bindgen", + "windows-link", ] [[package]] @@ -836,6 +849,30 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "2.1.1" @@ -1023,6 +1060,7 @@ name = "koucha" version = "0.1.0" dependencies = [ "axum", + "chrono", "reqwest", "rss", "sqlx", @@ -2547,6 +2585,41 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" version = "0.2.1" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index 4198f3f..186198f 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -9,3 +9,4 @@ reqwest = "0.13.1" rss = "2.0.12" tokio = { version = "1.49.0", features = ["full"] } sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } +chrono = "0.4.43" diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 392e221..961ad1d 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -1,9 +1,12 @@ -use std::error::Error; -use reqwest::{ - IntoUrl, - Client, +use std::{ + error::Error, + hash::{Hash, Hasher}, +}; +use reqwest::Url; +use chrono::{ + Utc, + DateTime, }; -use rss::Channel as RawChannel; type Result = std::result::Result>; @@ -26,33 +29,42 @@ impl AdapterOptions { pub async fn create(self) -> Result { let db = sqlx::sqlite::SqlitePoolOptions::new() .connect(&self.database_url).await?; + let client = reqwest::Client::new(); - Ok(Adapter { db }) + Ok(Adapter { db, client }) } } pub struct Adapter { db: sqlx::SqlitePool, + client: reqwest::Client, } impl Adapter { pub async fn get_all_users(&self) -> Result> { - let users_query = sqlx::query!("SELECT id, name FROM users") - .fetch_all(&self.db).await?; + let users = sqlx::query_as!( + User, + "SELECT id, name FROM users" + ).fetch_all(&self.db).await?; - let mut all_users: Vec = Vec::with_capacity(users_query.len()); - - for user in users_query { - all_users.push(User { - id: user.id, - name: user.name, - }) - } - - Ok(all_users) + Ok(users) } + // pub async fn update_channels(&self) -> Result<()> { + // + // } + // + // async fn get_all_channels(&self) -> Result> { + // let users = sqlx::query_as!( + // Channel, + // "SELECT id FROM channels" + // ).fetch_all(&self.db).await?; + // + // Ok(users) + // } + fn get_pool(&self) -> &sqlx::SqlitePool { &self.db } + fn get_client(&self) -> &reqwest::client { &self.client } } pub struct User { @@ -61,15 +73,15 @@ pub struct User { } impl User { - pub async fn get_by_id(adapter: &Adapter, id: i64) -> Result { - let user = sqlx::query!("SELECT name FROM users WHERE id = ?", id) - .fetch_one(adapter.get_pool()).await?; - - Ok(Self { - id: id, - name: user.name, - }) - } + // async fn get_by_id(adapter: &Adapter, id: i64) -> Result { + // let user = sqlx::query!("SELECT name FROM users WHERE id = ?", id) + // .fetch_one(adapter.get_pool()).await?; + // + // Ok(Self { + // id: id, + // name: user.name, + // }) + // } pub async fn create(adapter: &Adapter, name: &str) -> Result { let result = sqlx::query!("INSERT INTO users (name) VALUES (?)", name) @@ -93,21 +105,123 @@ impl User { Ok(()) } + pub async fn get_feeds(&self, adapter: &Adapter) -> Result> { + let feeds = sqlx::query_as!( + Feed, + "SELECT id FROM feeds WHERE user_id = ?", + self.id + ).fetch_all(adapter.get_pool()).await?; + + Ok(feeds) + } + pub fn name(&self) -> &str { &self.name } - pub fn id(&self) -> i64 { self.id } +} + +pub struct Feed { + id: i64, +} + +impl Feed { + pub async fn get_items( + &self, adapter: &Adapter, limit: u8, offset: u32) -> Result> { + let items = sqlx::query_as!( + Item, + "SELECT item_id as id FROM feed_items + WHERE feed_id = ? AND archived = FALSE + ORDER BY score DESC + LIMIT ? OFFSET ?", + self.id, limit, offset + ).fetch_all(adapter.get_pool()).await?; + + Ok(items) + } + + pub async fn get_channels(&self, adapter: &Adapter) -> Result> { + let db_channels = sqlx::query!( + "SELECT c.id as `id!`, c.title, c.link, c.description, c.last_fetched + FROM channels c + JOIN feed_channels fc on c.id = fc.channel_id + WHERE fc.feed_id = ?", + self.id + ).fetch_all(adapter.get_pool()).await?; + let mut channels = Vec::with_capacity(db_channels.len()); + for db_channel in db_channels { + channels.push(Channel { + id: db_channel.id, + title: db_channel.title, + link: Url::parse(&db_channel.link)?, + description: db_channel.description, + last_fetched: db_channel.last_fetched.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), + }) + } + Ok(channels) + } } pub struct Channel { - pub channel: rss::Channel, + id: i64, + title: String, + link: Url, + description: Option, + last_fetched: Option>, } -pub async fn fetch_channel( - client: &Client, url: T) -> Result { - let content = client.get(url) - .send().await? - .bytes().await?; +impl Channel { + pub async fn fetch(mut self, adapter: &Adapter) -> Result { + let bytestream = adapter.get_client().get(self.link.clone()) + .send().await? + .bytes().await?; - let raw_channel = RawChannel::read_from(&content[..])?; - println!("{}", raw_channel.title); - Ok(Channel { channel: raw_channel }) + let rss_channel = rss::Channel::read_from(&bytestream[..])?; + self.title = rss_channel.title; + self.link = Url::parse(&rss_channel.link)?; + self.description = Some(rss_channel.description); + let now = Utc::now(); + self.last_fetched = Some(now); + + sqlx::query!( + "UPDATE channels + SET title = ?, link = ?, description = ?, + last_fetched = ? + WHERE id = ?", + self.title, self.link.as_str(), self.description, now.to_rfc2822(), + self.id + ).execute(adapter.get_pool()).await?; + + fn get_or_create_guid(item: &rss::Item) -> String { + if let Some(guid) = item.guid() { + return guid.value().to_string(); + } + + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + item.link().unwrap_or("").hash(&mut hasher); + item.title().unwrap_or("").hash(&mut hasher); + item.description().unwrap_or("").hash(&mut hasher); + + format!("gen-{:x}", hasher.finish()) + } + + for item in rss_channel.items { + sqlx::query!( + "INSERT OR IGNORE INTO items + (channel_id, guid, fetched_at, title, description, content) + VALUES (?, ?, ?, ?, ?, ?)", + self.id, get_or_create_guid(&item), now.to_rfc2822(), + item.title().unwrap_or(""), item.description().unwrap_or(""), + item.content().unwrap_or("") + ) + .execute(adapter.get_pool()) + .await?; + } + + Ok(self) + } +} + +pub struct Item { + id: i64, } From 440e897edfa70a2910c67f4b1e531899bc56c49a Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 20 Jan 2026 16:08:36 -0800 Subject: [PATCH 07/32] Modulified it --- koucha/src/bin/server.rs | 9 +- koucha/src/channel.rs | 164 +++++++++++++++++++++++++++++++ koucha/src/feed.rs | 49 ++++++++++ koucha/src/item.rs | 3 + koucha/src/lib.rs | 204 +++------------------------------------ koucha/src/user.rs | 62 ++++++++++++ 6 files changed, 296 insertions(+), 195 deletions(-) create mode 100644 koucha/src/channel.rs create mode 100644 koucha/src/feed.rs create mode 100644 koucha/src/item.rs create mode 100644 koucha/src/user.rs diff --git a/koucha/src/bin/server.rs b/koucha/src/bin/server.rs index d4a8d34..4a05eed 100644 --- a/koucha/src/bin/server.rs +++ b/koucha/src/bin/server.rs @@ -1,11 +1,14 @@ use std::error::Error; use reqwest::Client; -use koucha::fetch_channel; +use koucha::{ + AdapterOptions, +}; #[tokio::main] async fn main() -> Result<(), Box> { - let client = Client::new(); - let _channel = fetch_channel(&client, "https://lorem-rss.herokuapp.com/feed?unit=year").await?; + // let adapter = AdapterOptions::new().create().await?; + // + // let _channel = fetch_channel(&client, "https://lorem-rss.herokuapp.com/feed?unit=year").await?; Ok(()) } diff --git a/koucha/src/channel.rs b/koucha/src/channel.rs new file mode 100644 index 0000000..73eada0 --- /dev/null +++ b/koucha/src/channel.rs @@ -0,0 +1,164 @@ +use reqwest::{Url, Client}; +use sqlx::SqlitePool; +use chrono::{DateTime, Utc}; +use crate::{Result}; +use std::hash::{Hash, Hasher}; + +pub struct ChannelId(pub i64); +impl From for ChannelId { fn from(id: i64) -> Self { ChannelId(id) } } +impl From for i64 { fn from(id: ChannelId) -> Self { id.0 } } + + +struct FetchedRSSItem { + guid: String, + title: String, + description: String, + content: String, +} +impl FetchedRSSItem { + fn parse(item: rss::Item) -> Self { + FetchedRSSItem { + guid: Self::get_or_create_guid(&item), + title: item.title().unwrap_or("").to_string(), + description: item.description().unwrap_or("").to_string(), + content: item.content().unwrap_or("").to_string(), + } + } + + fn get_or_create_guid(item: &rss::Item) -> String { + if let Some(guid) = item.guid() { + return guid.value().to_string(); + } + + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + item.link().unwrap_or("").hash(&mut hasher); + item.title().unwrap_or("").hash(&mut hasher); + item.description().unwrap_or("").hash(&mut hasher); + + format!("gen-{:x}", hasher.finish()) + } +} +pub struct FetchedRSSChannel { + title: String, + link: Url, + description: String, + + items: Vec, + + fetched_at: DateTime, +} +impl FetchedRSSChannel { + pub fn fetched_at(&self) -> &DateTime { + &self.fetched_at + } + + fn parse(rss: rss::Channel) -> Result { + Ok(FetchedRSSChannel { + title: rss.title, + link: Url::parse(&rss.link)?, + description: rss.description, + + items: rss.items.into_iter().map(FetchedRSSItem::parse).collect(), + + fetched_at: Utc::now(), + }) + } +} + +pub struct UnparsedChannel { + pub id: i64, + pub title: String, + pub link: String, + pub description: Option, + pub last_fetched: Option, +} +impl UnparsedChannel { + pub fn parse(self) -> Result { + Ok(Channel { + id: ChannelId(self.id), + title: self.title, + link: Url::parse(&self.link)?, + description: self.description, + last_fetched: self.last_fetched.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), + }) + } +} + +pub struct Channel { + pub id: ChannelId, + pub title: String, + pub link: Url, + pub description: Option, + pub last_fetched: Option>, +} + +impl Channel { + pub async fn get_all(pool: &SqlitePool) -> Result> { + let channels: Result> = sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched FROM channels" + ) + .fetch_all(pool).await?.into_iter() + .map(UnparsedChannel::parse).collect(); + + channels + } + + // TODO implement fetch skipping + fn should_skip_fetch(&self) -> bool { false } + + // TODO implement conditional fetching + pub async fn fetch_rss( + client: &Client, channel: &Channel + ) -> Result> { + if channel.should_skip_fetch() { + return Ok(None); + } + let bytestream = client.get(channel.link.clone()) + .send().await? + .bytes().await?; + + let rss_channel = rss::Channel::read_from(&bytestream[..])?; + + Ok(Some(FetchedRSSChannel::parse(rss_channel)?)) + } + + pub async fn update_metadata( + pool: &SqlitePool, id: ChannelId, fetched: FetchedRSSChannel + ) -> Result<()> { + let link = fetched.link.as_str(); + let fetched_at = fetched.fetched_at.to_rfc2822(); + sqlx::query!( + "UPDATE channels + SET title = ?, link = ?, description = ?, + last_fetched = ? + WHERE id = ?", + fetched.title, link, fetched.description, fetched_at, + id.0 + ).execute(pool).await?; + + Ok(()) + } + + pub async fn update_items( + pool: &SqlitePool, id: ChannelId, fetched: FetchedRSSChannel + ) -> Result<()> { + let fetched_at = fetched.fetched_at.to_rfc2822(); + + for item in fetched.items { + sqlx::query!( + "INSERT OR IGNORE INTO items + (channel_id, guid, fetched_at, title, description, content) + VALUES (?, ?, ?, ?, ?, ?)", + id.0, item.guid, fetched_at, item.title, item.description, item.content + ) + .execute(pool) + .await?; + } + + Ok(()) + } +} diff --git a/koucha/src/feed.rs b/koucha/src/feed.rs new file mode 100644 index 0000000..aaafa90 --- /dev/null +++ b/koucha/src/feed.rs @@ -0,0 +1,49 @@ +use crate::{ + Result, + Item, + Channel, + channel::UnparsedChannel, +}; +use sqlx::SqlitePool; + +pub struct FeedId(pub i64); +impl From for FeedId { fn from(id: i64) -> Self { FeedId(id) } } +impl From for i64 { fn from(id: FeedId) -> Self { id.0 } } + +pub struct Feed { + pub id: FeedId, +} + +impl Feed { + pub async fn get_items( + pool: &SqlitePool, id: FeedId, limit: u8, offset: u32 + ) -> Result> { + let items = sqlx::query_as!( + Item, + "SELECT item_id as id FROM feed_items + WHERE feed_id = ? AND archived = FALSE + ORDER BY score DESC + LIMIT ? OFFSET ?", + id.0, limit, offset + ).fetch_all(pool).await?; + + Ok(items) + } + + pub async fn get_channels( + pool: &SqlitePool, id: FeedId + ) -> Result> { + let channels: Result> = sqlx::query_as!( + UnparsedChannel, + "SELECT c.id as `id!`, c.title, c.link, c.description, c.last_fetched + FROM channels c + JOIN feed_channels fc on c.id = fc.channel_id + WHERE fc.feed_id = ?", + id.0 + ).fetch_all(pool).await?.into_iter() + .map(UnparsedChannel::parse).collect(); + + channels + } +} + diff --git a/koucha/src/item.rs b/koucha/src/item.rs new file mode 100644 index 0000000..0d2a7ab --- /dev/null +++ b/koucha/src/item.rs @@ -0,0 +1,3 @@ +pub struct Item { + pub id: i64, +} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 961ad1d..d12c88e 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -1,15 +1,16 @@ -use std::{ - error::Error, - hash::{Hash, Hasher}, -}; -use reqwest::Url; -use chrono::{ - Utc, - DateTime, -}; +use std::error::Error; type Result = std::result::Result>; +mod user; +pub use user::User; +mod feed; +pub use feed::Feed; +mod channel; +pub use channel::Channel; +mod item; +pub use item::Item; + pub struct AdapterOptions { database_url: String, } @@ -41,187 +42,6 @@ pub struct Adapter { } impl Adapter { - pub async fn get_all_users(&self) -> Result> { - let users = sqlx::query_as!( - User, - "SELECT id, name FROM users" - ).fetch_all(&self.db).await?; - - Ok(users) - } - - // pub async fn update_channels(&self) -> Result<()> { - // - // } - // - // async fn get_all_channels(&self) -> Result> { - // let users = sqlx::query_as!( - // Channel, - // "SELECT id FROM channels" - // ).fetch_all(&self.db).await?; - // - // Ok(users) - // } - - fn get_pool(&self) -> &sqlx::SqlitePool { &self.db } - fn get_client(&self) -> &reqwest::client { &self.client } -} - -pub struct User { - id: i64, - name: String, -} - -impl User { - // async fn get_by_id(adapter: &Adapter, id: i64) -> Result { - // let user = sqlx::query!("SELECT name FROM users WHERE id = ?", id) - // .fetch_one(adapter.get_pool()).await?; - // - // Ok(Self { - // id: id, - // name: user.name, - // }) - // } - - pub async fn create(adapter: &Adapter, name: &str) -> Result { - let result = sqlx::query!("INSERT INTO users (name) VALUES (?)", name) - .execute(adapter.get_pool()).await?; - - Ok(Self { - id: result.last_insert_rowid(), - name: name.to_string() - }) - } - - pub async fn change_name( - &mut self, adapter: &Adapter, new_name: &str) -> Result<()> { - sqlx::query!( - "UPDATE users SET name = ? WHERE id = ?", - new_name, self.id - ).execute(adapter.get_pool()).await?; - - self.name = new_name.to_string(); - - Ok(()) - } - - pub async fn get_feeds(&self, adapter: &Adapter) -> Result> { - let feeds = sqlx::query_as!( - Feed, - "SELECT id FROM feeds WHERE user_id = ?", - self.id - ).fetch_all(adapter.get_pool()).await?; - - Ok(feeds) - } - - pub fn name(&self) -> &str { &self.name } -} - -pub struct Feed { - id: i64, -} - -impl Feed { - pub async fn get_items( - &self, adapter: &Adapter, limit: u8, offset: u32) -> Result> { - let items = sqlx::query_as!( - Item, - "SELECT item_id as id FROM feed_items - WHERE feed_id = ? AND archived = FALSE - ORDER BY score DESC - LIMIT ? OFFSET ?", - self.id, limit, offset - ).fetch_all(adapter.get_pool()).await?; - - Ok(items) - } - - pub async fn get_channels(&self, adapter: &Adapter) -> Result> { - let db_channels = sqlx::query!( - "SELECT c.id as `id!`, c.title, c.link, c.description, c.last_fetched - FROM channels c - JOIN feed_channels fc on c.id = fc.channel_id - WHERE fc.feed_id = ?", - self.id - ).fetch_all(adapter.get_pool()).await?; - let mut channels = Vec::with_capacity(db_channels.len()); - for db_channel in db_channels { - channels.push(Channel { - id: db_channel.id, - title: db_channel.title, - link: Url::parse(&db_channel.link)?, - description: db_channel.description, - last_fetched: db_channel.last_fetched.as_deref() - .map(DateTime::parse_from_rfc2822) - .transpose()? - .map(|dt| dt.with_timezone(&Utc)), - }) - } - Ok(channels) - } -} - -pub struct Channel { - id: i64, - title: String, - link: Url, - description: Option, - last_fetched: Option>, -} - -impl Channel { - pub async fn fetch(mut self, adapter: &Adapter) -> Result { - let bytestream = adapter.get_client().get(self.link.clone()) - .send().await? - .bytes().await?; - - let rss_channel = rss::Channel::read_from(&bytestream[..])?; - self.title = rss_channel.title; - self.link = Url::parse(&rss_channel.link)?; - self.description = Some(rss_channel.description); - let now = Utc::now(); - self.last_fetched = Some(now); - - sqlx::query!( - "UPDATE channels - SET title = ?, link = ?, description = ?, - last_fetched = ? - WHERE id = ?", - self.title, self.link.as_str(), self.description, now.to_rfc2822(), - self.id - ).execute(adapter.get_pool()).await?; - - fn get_or_create_guid(item: &rss::Item) -> String { - if let Some(guid) = item.guid() { - return guid.value().to_string(); - } - - let mut hasher = std::collections::hash_map::DefaultHasher::new(); - item.link().unwrap_or("").hash(&mut hasher); - item.title().unwrap_or("").hash(&mut hasher); - item.description().unwrap_or("").hash(&mut hasher); - - format!("gen-{:x}", hasher.finish()) - } - - for item in rss_channel.items { - sqlx::query!( - "INSERT OR IGNORE INTO items - (channel_id, guid, fetched_at, title, description, content) - VALUES (?, ?, ?, ?, ?, ?)", - self.id, get_or_create_guid(&item), now.to_rfc2822(), - item.title().unwrap_or(""), item.description().unwrap_or(""), - item.content().unwrap_or("") - ) - .execute(adapter.get_pool()) - .await?; - } - - Ok(self) - } -} - -pub struct Item { - id: i64, + pub fn get_pool(&self) -> &sqlx::SqlitePool { &self.db } + pub fn get_client(&self) -> &reqwest::Client { &self.client } } diff --git a/koucha/src/user.rs b/koucha/src/user.rs new file mode 100644 index 0000000..5a038a0 --- /dev/null +++ b/koucha/src/user.rs @@ -0,0 +1,62 @@ +use sqlx::SqlitePool; +use crate::{ + Result, + Feed +}; + +pub struct UserId(pub i64); +impl From for UserId { fn from(id: i64) -> Self { UserId(id) } } +impl From for i64 { fn from(id: UserId) -> Self { id.0 } } + +pub struct User { + pub id: UserId, + pub name: String, +} + +impl User { + pub async fn get_all(pool: &SqlitePool) -> Result> { + let users = sqlx::query_as!( + User, + "SELECT id, name FROM users" + ).fetch_all(pool).await?; + + Ok(users) + } + + pub async fn create(pool: &SqlitePool, name: &str) -> Result { + let result = sqlx::query!( + "INSERT INTO users (name) + VALUES (?) + RETURNING id, name", + name + ).fetch_one(pool).await?; + + Ok(Self { + id: UserId(result.id), + name: result.name, + }) + } + + pub async fn update_name( + pool: &SqlitePool, id: UserId, new_name: &str + ) -> Result<()> { + sqlx::query!( + "UPDATE users SET name = ? WHERE id = ?", + new_name, id.0 + ).execute(pool).await?; + + Ok(()) + } + + pub async fn get_feeds(pool: &SqlitePool, id: UserId) -> Result> { + let feeds = sqlx::query_as!( + Feed, + "SELECT id FROM feeds WHERE user_id = ?", + id.0 + ).fetch_all(pool).await?; + + Ok(feeds) + } + + pub fn name(&self) -> &str { &self.name } +} From 162ba7843047b1545cbe8cc235267dbbd65c0265 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 20 Jan 2026 16:36:14 -0800 Subject: [PATCH 08/32] Adding fill functions --- .../20260115003047_initial_schema.sql | 1 + koucha/src/channel.rs | 4 +- koucha/src/feed.rs | 51 ++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql index d437df3..25122e7 100644 --- a/koucha/migrations/20260115003047_initial_schema.sql +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -32,6 +32,7 @@ CREATE TABLE items ( CREATE TABLE feeds ( id INTEGER PRIMARY KEY, user_id INTEGER NOT NULL, + title TEXT NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ); diff --git a/koucha/src/channel.rs b/koucha/src/channel.rs index 73eada0..6d130ff 100644 --- a/koucha/src/channel.rs +++ b/koucha/src/channel.rs @@ -40,7 +40,7 @@ impl FetchedRSSItem { } pub struct FetchedRSSChannel { title: String, - link: Url, + link: Url, description: String, items: Vec, @@ -96,6 +96,8 @@ pub struct Channel { } impl Channel { + + pub async fn get_all(pool: &SqlitePool) -> Result> { let channels: Result> = sqlx::query_as!( UnparsedChannel, diff --git a/koucha/src/feed.rs b/koucha/src/feed.rs index aaafa90..8e04a0d 100644 --- a/koucha/src/feed.rs +++ b/koucha/src/feed.rs @@ -2,7 +2,11 @@ use crate::{ Result, Item, Channel, - channel::UnparsedChannel, + channel::{ + UnparsedChannel, + ChannelId, + }, + user::UserId, }; use sqlx::SqlitePool; @@ -10,17 +14,60 @@ pub struct FeedId(pub i64); impl From for FeedId { fn from(id: i64) -> Self { FeedId(id) } } impl From for i64 { fn from(id: FeedId) -> Self { id.0 } } +pub struct UnparsedFeed { + pub id: i64, + pub title: String, + pub user_id: i64 +} +impl UnparsedFeed { + pub fn parse(self) -> Result { + Ok(Feed { + id: FeedId(self.id), + title: self.title, + user_id: UserId(self.user_id), + }) + } +} + pub struct Feed { pub id: FeedId, + pub title: String, + pub user_id: UserId, } impl Feed { + pub async fn create( + pool: &SqlitePool, id: UserId, name: &str + ) -> Result { + let new_feed = sqlx::query_as!( + UnparsedFeed, + "INSERT INTO feeds (user_id, title) + VALUES (?, ?) + RETURNING id as `id!`, user_id, title", + id.0, name + ).fetch_one(pool).await?.parse(); + + new_feed + } + + pub async fn add_channel( + pool: &SqlitePool, id: FeedId, channel_id: ChannelId + ) -> Result<()> { + sqlx::query!( + "INSERT INTO feed_channels (feed_id, channel_id) + VALUES (?, ?)", + id.0, channel_id.0 + ).execute(pool).await?; + + Ok(()) + } + pub async fn get_items( pool: &SqlitePool, id: FeedId, limit: u8, offset: u32 ) -> Result> { let items = sqlx::query_as!( Item, - "SELECT item_id as id FROM feed_items + "SELECT item_id as id FROM feed_items WHERE feed_id = ? AND archived = FALSE ORDER BY score DESC LIMIT ? OFFSET ?", From e07a98ddbbb77957b1da63a60183cd76ff7d3b67 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Wed, 21 Jan 2026 12:47:47 -0800 Subject: [PATCH 09/32] Finalizing type schema and user tests --- koucha/src/feed.rs | 19 +++--- koucha/src/user.rs | 152 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 143 insertions(+), 28 deletions(-) diff --git a/koucha/src/feed.rs b/koucha/src/feed.rs index 8e04a0d..1a38d91 100644 --- a/koucha/src/feed.rs +++ b/koucha/src/feed.rs @@ -10,41 +10,42 @@ use crate::{ }; use sqlx::SqlitePool; -pub struct FeedId(pub i64); -impl From for FeedId { fn from(id: i64) -> Self { FeedId(id) } } +#[derive(Copy, Clone)] +pub struct FeedId(i64); impl From for i64 { fn from(id: FeedId) -> Self { id.0 } } pub struct UnparsedFeed { pub id: i64, pub title: String, - pub user_id: i64 } impl UnparsedFeed { pub fn parse(self) -> Result { Ok(Feed { id: FeedId(self.id), title: self.title, - user_id: UserId(self.user_id), }) } } pub struct Feed { - pub id: FeedId, - pub title: String, - pub user_id: UserId, + id: FeedId, + title: String, } impl Feed { + pub fn id(&self) -> FeedId { self.id } + pub fn title(&self) -> &str { &self.title } + pub async fn create( pool: &SqlitePool, id: UserId, name: &str ) -> Result { + let int_id = i64::from(id); let new_feed = sqlx::query_as!( UnparsedFeed, "INSERT INTO feeds (user_id, title) VALUES (?, ?) - RETURNING id as `id!`, user_id, title", - id.0, name + RETURNING id as `id!`, title", + int_id, name ).fetch_one(pool).await?.parse(); new_feed diff --git a/koucha/src/user.rs b/koucha/src/user.rs index 5a038a0..f78de6e 100644 --- a/koucha/src/user.rs +++ b/koucha/src/user.rs @@ -1,26 +1,52 @@ use sqlx::SqlitePool; use crate::{ Result, - Feed + Feed, + feed::UnparsedFeed, }; -pub struct UserId(pub i64); -impl From for UserId { fn from(id: i64) -> Self { UserId(id) } } +#[derive(Copy, Clone)] +pub struct UserId(i64); impl From for i64 { fn from(id: UserId) -> Self { id.0 } } -pub struct User { - pub id: UserId, +pub struct UnparsedUser { + pub id: i64, pub name: String, } +impl UnparsedUser { + pub fn parse(self) -> Result { + Ok(User { + id: UserId(self.id), + name: self.name + }) + } +} + +pub struct User { + id: UserId, + name: String, +} impl User { - pub async fn get_all(pool: &SqlitePool) -> Result> { - let users = sqlx::query_as!( - User, - "SELECT id, name FROM users" - ).fetch_all(pool).await?; + pub fn id(&self) -> UserId { self.id } + pub fn name(&self) -> &str { &self.name } - Ok(users) + pub async fn get(pool: &SqlitePool, id: UserId) -> Result { + let user = sqlx::query_as!( + UnparsedUser, + "SELECT id, name FROM users WHERE id = ?", + id.0 + ).fetch_one(pool).await?.parse(); + + user + } + pub async fn get_all(pool: &SqlitePool) -> Result> { + let users: Result> = sqlx::query_as!( + UnparsedUser, + "SELECT id, name FROM users" + ).fetch_all(pool).await?.into_iter().map(UnparsedUser::parse).collect(); + + users } pub async fn create(pool: &SqlitePool, name: &str) -> Result { @@ -48,15 +74,103 @@ impl User { Ok(()) } - pub async fn get_feeds(pool: &SqlitePool, id: UserId) -> Result> { - let feeds = sqlx::query_as!( - Feed, - "SELECT id FROM feeds WHERE user_id = ?", - id.0 - ).fetch_all(pool).await?; + pub async fn get_feeds(&self, pool: &SqlitePool) -> Result> { + let feeds: Result> = sqlx::query_as!( + UnparsedFeed, + "SELECT id, title FROM feeds WHERE user_id = ?", + self.id.0 + ).fetch_all(pool).await?.into_iter() + .map(UnparsedFeed::parse).collect(); - Ok(feeds) + feeds + } +} + +#[cfg(test)] +mod tests { + use super::*; + use sqlx::SqlitePool; + + async fn setup_test_db() -> SqlitePool { + let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); + sqlx::migrate!().run(&pool).await.unwrap(); + pool + } + + #[tokio::test] + async fn get_user() { + let pool = setup_test_db().await; + + let new_user = User::create(&pool, "Alice").await.unwrap(); + + let fetched_user = User::get(&pool, new_user.id).await.unwrap(); + assert_eq!(fetched_user.name, "Alice"); + assert!(fetched_user.id.0 > 0); } - pub fn name(&self) -> &str { &self.name } + #[tokio::test] + async fn create_user() { + let pool = setup_test_db().await; + + let user = User::create(&pool, "Alice").await.unwrap(); + + assert_eq!(user.name, "Alice"); + assert!(user.id.0 > 0); + } + + #[tokio::test] + async fn create_duplicate_user() { + let pool = setup_test_db().await; + + let _user = User::create(&pool, "Alice").await.unwrap(); + let duplicate_user = User::create(&pool, "Alice").await; + + assert!(duplicate_user.is_err()); + } + + #[tokio::test] + async fn get_all_users() { + let pool = setup_test_db().await; + + User::create(&pool, "Alice").await.unwrap(); + User::create(&pool, "Bob").await.unwrap(); + + let users = User::get_all(&pool).await.unwrap(); + + assert_eq!(users.len(), 2); + assert!(users.iter().any(|u| u.name == "Alice")); + assert!(users.iter().any(|u| u.name == "Bob")); + } + + #[tokio::test] + async fn update_name() { + let pool = setup_test_db().await; + + let user = User::create(&pool, "Alice").await.unwrap(); + User::update_name(&pool, user.id, "Alicia").await.unwrap(); + + let updated = User::get(&pool, user.id).await.unwrap(); + assert_eq!(updated.name, "Alicia"); + } + + #[tokio::test] + async fn update_name_to_duplicate() { + let pool = setup_test_db().await; + + let alice = User::create(&pool, "Alice").await.unwrap(); + let _sam = User::create(&pool, "Sam").await.unwrap(); + let status = User::update_name(&pool, alice.id, "Sam").await; + + assert!(status.is_err()); + } + + #[tokio::test] + async fn get_feeds_empty() { + let pool = setup_test_db().await; + + let user = User::create(&pool, "Alice").await.unwrap(); + let feeds = user.get_feeds(&pool).await.unwrap(); + + assert_eq!(feeds.len(), 0); + } } From d7123fb153d6fca3f5d792c299c971eb91c1cc4d Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Wed, 21 Jan 2026 13:04:51 -0800 Subject: [PATCH 10/32] Finalize feed, tests which don't need channel creation --- koucha/src/feed.rs | 78 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/koucha/src/feed.rs b/koucha/src/feed.rs index 1a38d91..56097fb 100644 --- a/koucha/src/feed.rs +++ b/koucha/src/feed.rs @@ -36,35 +36,58 @@ impl Feed { pub fn id(&self) -> FeedId { self.id } pub fn title(&self) -> &str { &self.title } - pub async fn create( - pool: &SqlitePool, id: UserId, name: &str + pub async fn get( + pool: &SqlitePool, id: FeedId ) -> Result { - let int_id = i64::from(id); + let feed = sqlx::query_as!( + UnparsedFeed, + "SELECT id, title FROM feeds WHERE id = ?", + id.0 + ).fetch_one(pool).await?.parse(); + + feed + } + + pub async fn create( + pool: &SqlitePool, user_id: UserId, title: &str + ) -> Result { + let int_id = i64::from(user_id); let new_feed = sqlx::query_as!( UnparsedFeed, "INSERT INTO feeds (user_id, title) VALUES (?, ?) RETURNING id as `id!`, title", - int_id, name + int_id, title ).fetch_one(pool).await?.parse(); new_feed } + pub async fn update_title( + pool: &SqlitePool, id: FeedId, new_title: &str + ) -> Result<()> { + sqlx::query!( + "UPDATE feeds SET title = ? WHERE id = ?", + new_title, id.0 + ).execute(pool).await?; + + Ok(()) + } + pub async fn add_channel( - pool: &SqlitePool, id: FeedId, channel_id: ChannelId + &self, pool: &SqlitePool, channel_id: ChannelId ) -> Result<()> { sqlx::query!( "INSERT INTO feed_channels (feed_id, channel_id) VALUES (?, ?)", - id.0, channel_id.0 + self.id.0, channel_id.0 ).execute(pool).await?; Ok(()) } pub async fn get_items( - pool: &SqlitePool, id: FeedId, limit: u8, offset: u32 + &self, pool: &SqlitePool, limit: u8, offset: u32 ) -> Result> { let items = sqlx::query_as!( Item, @@ -72,14 +95,14 @@ impl Feed { WHERE feed_id = ? AND archived = FALSE ORDER BY score DESC LIMIT ? OFFSET ?", - id.0, limit, offset + self.id.0, limit, offset ).fetch_all(pool).await?; Ok(items) } pub async fn get_channels( - pool: &SqlitePool, id: FeedId + &self, pool: &SqlitePool ) -> Result> { let channels: Result> = sqlx::query_as!( UnparsedChannel, @@ -87,7 +110,7 @@ impl Feed { FROM channels c JOIN feed_channels fc on c.id = fc.channel_id WHERE fc.feed_id = ?", - id.0 + self.id.0 ).fetch_all(pool).await?.into_iter() .map(UnparsedChannel::parse).collect(); @@ -95,3 +118,38 @@ impl Feed { } } +#[cfg(test)] +mod tests { + use super::*; + use crate::User; + use sqlx::SqlitePool; + + async fn setup_test_db() -> SqlitePool { + let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); + sqlx::migrate!().run(&pool).await.unwrap(); + pool + } + + #[tokio::test] + async fn create_feed() { + let pool = setup_test_db().await; + let user = User::create(&pool, "Alice").await.unwrap(); + + let feed = Feed::create(&pool, user.id(), "Tech News").await.unwrap(); + + assert_eq!(feed.title(), "Tech News"); + assert!(feed.id().0 > 0); + } + + #[tokio::test] + async fn test_update_title() { + let pool = setup_test_db().await; + let user = User::create(&pool, "Alice").await.unwrap(); + let feed = Feed::create(&pool, user.id(), "Tech News").await.unwrap(); + + Feed::update_title(&pool, feed.id(), "Technology").await.unwrap(); + + let updated = Feed::get(&pool, feed.id()).await.unwrap(); + assert_eq!(updated.title(), "Technology"); + } +} From 7bb4cf4230e77736180ae6afcbb0b13120536594 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 22 Jan 2026 10:39:38 -0800 Subject: [PATCH 11/32] Got the structure; got lots of tests; item still needs work --- koucha/src/channel.rs | 326 +++++++++++++++++++++++++++--------- koucha/src/channel/fetch.rs | 67 ++++++++ koucha/src/feed.rs | 12 +- koucha/src/item.rs | 19 ++- koucha/src/user.rs | 2 +- 5 files changed, 338 insertions(+), 88 deletions(-) create mode 100644 koucha/src/channel/fetch.rs diff --git a/koucha/src/channel.rs b/koucha/src/channel.rs index 6d130ff..b95b0b8 100644 --- a/koucha/src/channel.rs +++ b/koucha/src/channel.rs @@ -1,69 +1,18 @@ use reqwest::{Url, Client}; use sqlx::SqlitePool; use chrono::{DateTime, Utc}; -use crate::{Result}; -use std::hash::{Hash, Hasher}; +use crate::{ + Result, + Item, + channel::fetch::FetchedRSSChannel, + item::UnparsedItem, +}; -pub struct ChannelId(pub i64); -impl From for ChannelId { fn from(id: i64) -> Self { ChannelId(id) } } +#[derive(Copy, Clone)] +pub struct ChannelId(i64); impl From for i64 { fn from(id: ChannelId) -> Self { id.0 } } - -struct FetchedRSSItem { - guid: String, - title: String, - description: String, - content: String, -} -impl FetchedRSSItem { - fn parse(item: rss::Item) -> Self { - FetchedRSSItem { - guid: Self::get_or_create_guid(&item), - title: item.title().unwrap_or("").to_string(), - description: item.description().unwrap_or("").to_string(), - content: item.content().unwrap_or("").to_string(), - } - } - - fn get_or_create_guid(item: &rss::Item) -> String { - if let Some(guid) = item.guid() { - return guid.value().to_string(); - } - - let mut hasher = std::collections::hash_map::DefaultHasher::new(); - item.link().unwrap_or("").hash(&mut hasher); - item.title().unwrap_or("").hash(&mut hasher); - item.description().unwrap_or("").hash(&mut hasher); - - format!("gen-{:x}", hasher.finish()) - } -} -pub struct FetchedRSSChannel { - title: String, - link: Url, - description: String, - - items: Vec, - - fetched_at: DateTime, -} -impl FetchedRSSChannel { - pub fn fetched_at(&self) -> &DateTime { - &self.fetched_at - } - - fn parse(rss: rss::Channel) -> Result { - Ok(FetchedRSSChannel { - title: rss.title, - link: Url::parse(&rss.link)?, - description: rss.description, - - items: rss.items.into_iter().map(FetchedRSSItem::parse).collect(), - - fetched_at: Utc::now(), - }) - } -} +pub mod fetch; pub struct UnparsedChannel { pub id: i64, @@ -88,38 +37,77 @@ impl UnparsedChannel { } pub struct Channel { - pub id: ChannelId, - pub title: String, - pub link: Url, - pub description: Option, - pub last_fetched: Option>, + id: ChannelId, + title: String, + link: Url, + description: Option, + last_fetched: Option>, } impl Channel { - + pub fn id(&self) -> ChannelId { self.id } + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } pub async fn get_all(pool: &SqlitePool) -> Result> { let channels: Result> = sqlx::query_as!( UnparsedChannel, "SELECT id, title, link, description, last_fetched FROM channels" - ) - .fetch_all(pool).await?.into_iter() - .map(UnparsedChannel::parse).collect(); + ).fetch_all(pool).await?.into_iter().map(UnparsedChannel::parse).collect(); channels } + pub async fn get(pool: &SqlitePool, id: ChannelId) -> Result { + let channel: Result = sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched + FROM channels + WHERE id = ?", + id.0 + ).fetch_one(pool).await?.parse(); + + channel + } + + pub async fn create( + pool: &SqlitePool, link: Url + ) -> Result { + let link_str = link.as_str(); + + if let Ok(existing_channel) = sqlx::query_as!( + UnparsedChannel, + "SELECT id as `id!`, title, link, description, last_fetched + FROM channels + WHERE link = ?", + link_str + ).fetch_one(pool).await { + return existing_channel.parse(); + } + + let new_channel = sqlx::query_as!( + UnparsedChannel, + "INSERT INTO channels (title, link) + VALUES (?, ?) + RETURNING id, title, link, description, last_fetched", + link_str, link_str + ).fetch_one(pool).await?.parse(); + + new_channel + } + // TODO implement fetch skipping fn should_skip_fetch(&self) -> bool { false } // TODO implement conditional fetching pub async fn fetch_rss( - client: &Client, channel: &Channel + &self, client: &Client ) -> Result> { - if channel.should_skip_fetch() { + if self.should_skip_fetch() { return Ok(None); } - let bytestream = client.get(channel.link.clone()) + let bytestream = client.get(self.link.clone()) .send().await? .bytes().await?; @@ -129,33 +117,39 @@ impl Channel { } pub async fn update_metadata( - pool: &SqlitePool, id: ChannelId, fetched: FetchedRSSChannel + &self, pool: &SqlitePool, fetched: FetchedRSSChannel ) -> Result<()> { - let link = fetched.link.as_str(); - let fetched_at = fetched.fetched_at.to_rfc2822(); + let title = fetched.title(); + let description = fetched.description(); + let link = fetched.link().as_str(); + let fetched_at = fetched.fetched_at().to_rfc2822(); sqlx::query!( "UPDATE channels SET title = ?, link = ?, description = ?, last_fetched = ? WHERE id = ?", - fetched.title, link, fetched.description, fetched_at, - id.0 + title, link, description, fetched_at, + self.id.0 ).execute(pool).await?; Ok(()) } pub async fn update_items( - pool: &SqlitePool, id: ChannelId, fetched: FetchedRSSChannel + &self, pool: &SqlitePool, fetched: FetchedRSSChannel ) -> Result<()> { - let fetched_at = fetched.fetched_at.to_rfc2822(); + let fetched_at = fetched.fetched_at().to_rfc2822(); - for item in fetched.items { + for item in fetched.items() { + let guid = item.guid(); + let title = item.title(); + let description = item.description(); + let content = item.content(); sqlx::query!( "INSERT OR IGNORE INTO items (channel_id, guid, fetched_at, title, description, content) VALUES (?, ?, ?, ?, ?, ?)", - id.0, item.guid, fetched_at, item.title, item.description, item.content + self.id.0, guid, fetched_at, title, description, content ) .execute(pool) .await?; @@ -163,4 +157,174 @@ impl Channel { Ok(()) } + + pub async fn get_items(&self, pool: &SqlitePool) -> Result> { + let items: Result> = sqlx::query_as!( + UnparsedItem, + "SELECT id as `id!` FROM items WHERE channel_id = ?", + self.id.0 + ).fetch_all(pool).await?.into_iter().map(UnparsedItem::parse).collect(); + + items + } +} + +#[cfg(test)] +mod tests { + use super::*; + use rss::{ + Guid as RSSGuid, + Item as RSSItem, + ItemBuilder as RSSItemBuilder, + Channel as RSSChannel, + ChannelBuilder as RSSChannelBuilder, + }; + use sqlx::SqlitePool; + + const ITEM_TITLE: &str = "My Item"; + const ITEM_GUID1: &str = "https://mycontent.com/blog/1"; + const ITEM_GUID2: &str = "something-else!"; + const ITEM_DESC: &str = "A test item"; + const ITEM_CONT: &str = "some rss content baby"; + const CHAN_TITLE: &str = "My Feed"; + const CHAN_DESC: &str = "A test feed"; + const FEED1: &str = "https://example.com/feed"; + const FEED2: &str = "https://example2.com/feed"; + + async fn setup_test_db() -> SqlitePool { + let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); + sqlx::migrate!().run(&pool).await.unwrap(); + pool + } + + #[tokio::test] + async fn create_channel() { + let pool = setup_test_db().await; + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::create(&pool, url_feed).await.unwrap(); + + assert!(channel.id().0 > 0); + assert_eq!(channel.link().as_str(), FEED1); + assert!(channel.title().len() > 0); + } + + #[tokio::test] + async fn create_duplicate_returns_existing() { + let pool = setup_test_db().await; + let url_feed = Url::parse(FEED1).unwrap(); + + let channel1 = Channel::create(&pool, url_feed.clone()).await.unwrap(); + let channel2 = Channel::create(&pool, url_feed).await.unwrap(); + + assert_eq!( + i64::from(channel1.id()), + i64::from(channel2.id()) + ); + } + + #[tokio::test] + async fn get_all_channels() { + let pool = setup_test_db().await; + let url_feed1 = Url::parse(FEED1).unwrap(); + let url_feed2 = Url::parse(FEED2).unwrap(); + + Channel::create(&pool, url_feed1).await.unwrap(); + Channel::create(&pool, url_feed2).await.unwrap(); + + let channels = Channel::get_all(&pool).await.unwrap(); + + assert_eq!(channels.len(), 2); + } + + #[tokio::test] + async fn update_metadata() { + let pool = setup_test_db().await; + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::create(&pool, url_feed).await.unwrap(); + + let fake_rss: RSSChannel = RSSChannelBuilder::default() + .title(CHAN_TITLE) + .link(FEED2) + .description(CHAN_DESC) + .build(); + + let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); + + channel.update_metadata(&pool, fetched).await.unwrap(); + + let updated = Channel::get(&pool, channel.id()).await.unwrap(); + assert_eq!(updated.title(), CHAN_TITLE); + assert_eq!(updated.link().as_str(), FEED2); + assert_eq!(updated.description(), Some(CHAN_DESC)); + } + + #[tokio::test] + async fn update_items() { + let pool = setup_test_db().await; + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::create(&pool, url_feed).await.unwrap(); + + let item1: RSSItem = RSSItemBuilder::default() + .title(ITEM_TITLE.to_string()) + .description(ITEM_DESC.to_string()) + .content(ITEM_CONT.to_string()) + .guid(RSSGuid { value: ITEM_GUID1.to_string(), permalink: false }) + .build(); + let item2: RSSItem = RSSItemBuilder::default() + .title(ITEM_TITLE.to_string()) + .description(ITEM_DESC.to_string()) + .content(ITEM_CONT.to_string()) + .guid(RSSGuid { value: ITEM_GUID2.to_string(), permalink: false }) + .build(); + + let fake_rss: RSSChannel = RSSChannelBuilder::default() + .title(CHAN_TITLE) + .link(FEED2) + .description(CHAN_DESC) + .item(item1) + .item(item2) + .build(); + + let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); + + channel.update_items(&pool, fetched).await.unwrap(); + + let items = channel.get_items(&pool).await.unwrap(); + assert_eq!(items.len(), 2); + } + + #[tokio::test] + async fn update_items_ignores_duplicates() { + let pool = setup_test_db().await; + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::create(&pool, url_feed).await.unwrap(); + + let item1: RSSItem = RSSItemBuilder::default() + .title(ITEM_TITLE.to_string()) + .description(ITEM_DESC.to_string()) + .content(ITEM_CONT.to_string()) + .guid(RSSGuid { value: ITEM_GUID1.to_string(), permalink: false }) + .build(); + + let fake_rss: RSSChannel = RSSChannelBuilder::default() + .title(CHAN_TITLE) + .link(FEED2) + .description(CHAN_DESC) + .item(item1) + .build(); + + let fetched = FetchedRSSChannel::parse(fake_rss.clone()).unwrap(); + + channel.update_items(&pool, fetched).await.unwrap(); + let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); + + channel.update_items(&pool, fetched).await.unwrap(); + + let items = channel.get_items(&pool).await.unwrap(); + assert_eq!(items.len(), 1); + } } diff --git a/koucha/src/channel/fetch.rs b/koucha/src/channel/fetch.rs new file mode 100644 index 0000000..b660cfe --- /dev/null +++ b/koucha/src/channel/fetch.rs @@ -0,0 +1,67 @@ +use crate::Result; +use reqwest::Url; +use chrono::{DateTime, Utc}; +use std::hash::{Hash, Hasher}; + +pub struct FetchedRSSItem { + guid: String, + title: String, + description: String, + content: String, +} +impl FetchedRSSItem { + pub fn guid(&self) -> &str { &self.guid } + pub fn title(&self) -> &str { &self.title } + pub fn description(&self) -> &str { &self.description } + pub fn content(&self) -> &str { &self.content } + + fn parse(item: rss::Item) -> Self { + FetchedRSSItem { + guid: Self::get_or_create_guid(&item), + title: item.title().unwrap_or("").to_string(), + description: item.description().unwrap_or("").to_string(), + content: item.content().unwrap_or("").to_string(), + } + } + + fn get_or_create_guid(item: &rss::Item) -> String { + if let Some(guid) = item.guid() { + return guid.value().to_string(); + } + + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + item.link().unwrap_or("").hash(&mut hasher); + item.title().unwrap_or("").hash(&mut hasher); + item.description().unwrap_or("").hash(&mut hasher); + + format!("gen-{:x}", hasher.finish()) + } +} +pub struct FetchedRSSChannel { + title: String, + link: Url, + description: String, + + items: Vec, + + fetched_at: DateTime, +} +impl FetchedRSSChannel { + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> &str { &self.description } + pub fn items(&self) -> &[FetchedRSSItem] { &self.items } + pub fn fetched_at(&self) -> &DateTime { &self.fetched_at } + + pub fn parse(rss: rss::Channel) -> Result { + Ok(FetchedRSSChannel { + title: rss.title, + link: Url::parse(&rss.link)?, + description: rss.description, + + items: rss.items.into_iter().map(FetchedRSSItem::parse).collect(), + + fetched_at: Utc::now(), + }) + } +} diff --git a/koucha/src/feed.rs b/koucha/src/feed.rs index 56097fb..8e33b92 100644 --- a/koucha/src/feed.rs +++ b/koucha/src/feed.rs @@ -1,6 +1,7 @@ use crate::{ Result, Item, + item::UnparsedItem, Channel, channel::{ UnparsedChannel, @@ -77,10 +78,11 @@ impl Feed { pub async fn add_channel( &self, pool: &SqlitePool, channel_id: ChannelId ) -> Result<()> { + let int_channel_id = i64::from(channel_id); sqlx::query!( "INSERT INTO feed_channels (feed_id, channel_id) VALUES (?, ?)", - self.id.0, channel_id.0 + self.id.0, int_channel_id ).execute(pool).await?; Ok(()) @@ -89,16 +91,16 @@ impl Feed { pub async fn get_items( &self, pool: &SqlitePool, limit: u8, offset: u32 ) -> Result> { - let items = sqlx::query_as!( - Item, + let items: Result> = sqlx::query_as!( + UnparsedItem, "SELECT item_id as id FROM feed_items WHERE feed_id = ? AND archived = FALSE ORDER BY score DESC LIMIT ? OFFSET ?", self.id.0, limit, offset - ).fetch_all(pool).await?; + ).fetch_all(pool).await?.into_iter().map(UnparsedItem::parse).collect(); - Ok(items) + items } pub async fn get_channels( diff --git a/koucha/src/item.rs b/koucha/src/item.rs index 0d2a7ab..4d6af9f 100644 --- a/koucha/src/item.rs +++ b/koucha/src/item.rs @@ -1,3 +1,20 @@ -pub struct Item { +use crate::Result; + +#[derive(Copy, Clone)] +pub struct ItemId(i64); +impl From for i64 { fn from(id: ItemId) -> Self { id.0 } } + +pub struct UnparsedItem { pub id: i64, } +impl UnparsedItem { + pub fn parse(self) -> Result { + Ok(Item { + id: ItemId(self.id), + }) + } +} + +pub struct Item { + id: ItemId, +} diff --git a/koucha/src/user.rs b/koucha/src/user.rs index f78de6e..fc4e6ad 100644 --- a/koucha/src/user.rs +++ b/koucha/src/user.rs @@ -51,7 +51,7 @@ impl User { pub async fn create(pool: &SqlitePool, name: &str) -> Result { let result = sqlx::query!( - "INSERT INTO users (name) + "INSERT INTO users (name) VALUES (?) RETURNING id, name", name From f5fc83a471589fc0fac9c8ce021714b6f8f4ffdb Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 22 Jan 2026 11:39:33 -0800 Subject: [PATCH 12/32] Clean up server.rs, add DB and Client aliases --- koucha/src/bin/server.rs | 7 --- koucha/src/channel.rs | 95 +++++++++++++++++++++------------------- koucha/src/feed.rs | 55 +++++++++++------------ koucha/src/lib.rs | 39 ++++++++++++----- koucha/src/user.rs | 85 ++++++++++++++++++----------------- 5 files changed, 153 insertions(+), 128 deletions(-) diff --git a/koucha/src/bin/server.rs b/koucha/src/bin/server.rs index 4a05eed..5ca7b99 100644 --- a/koucha/src/bin/server.rs +++ b/koucha/src/bin/server.rs @@ -1,14 +1,7 @@ use std::error::Error; -use reqwest::Client; -use koucha::{ - AdapterOptions, -}; #[tokio::main] async fn main() -> Result<(), Box> { - // let adapter = AdapterOptions::new().create().await?; - // - // let _channel = fetch_channel(&client, "https://lorem-rss.herokuapp.com/feed?unit=year").await?; Ok(()) } diff --git a/koucha/src/channel.rs b/koucha/src/channel.rs index b95b0b8..da61531 100644 --- a/koucha/src/channel.rs +++ b/koucha/src/channel.rs @@ -1,8 +1,9 @@ -use reqwest::{Url, Client}; -use sqlx::SqlitePool; +use reqwest::Url; use chrono::{DateTime, Utc}; use crate::{ Result, + AdapterPool, + AdapterClient, Item, channel::fetch::FetchedRSSChannel, item::UnparsedItem, @@ -50,29 +51,29 @@ impl Channel { pub fn link(&self) -> &Url { &self.link } pub fn description(&self) -> Option<&str> { self.description.as_deref() } - pub async fn get_all(pool: &SqlitePool) -> Result> { + pub async fn get_all(pool: &AdapterPool) -> Result> { let channels: Result> = sqlx::query_as!( UnparsedChannel, "SELECT id, title, link, description, last_fetched FROM channels" - ).fetch_all(pool).await?.into_iter().map(UnparsedChannel::parse).collect(); + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedChannel::parse).collect(); channels } - pub async fn get(pool: &SqlitePool, id: ChannelId) -> Result { + pub async fn get(pool: &AdapterPool, id: ChannelId) -> Result { let channel: Result = sqlx::query_as!( UnparsedChannel, "SELECT id, title, link, description, last_fetched FROM channels WHERE id = ?", id.0 - ).fetch_one(pool).await?.parse(); + ).fetch_one(&pool.0).await?.parse(); channel } pub async fn create( - pool: &SqlitePool, link: Url + pool: &AdapterPool, link: Url ) -> Result { let link_str = link.as_str(); @@ -82,7 +83,7 @@ impl Channel { FROM channels WHERE link = ?", link_str - ).fetch_one(pool).await { + ).fetch_one(&pool.0).await { return existing_channel.parse(); } @@ -92,7 +93,7 @@ impl Channel { VALUES (?, ?) RETURNING id, title, link, description, last_fetched", link_str, link_str - ).fetch_one(pool).await?.parse(); + ).fetch_one(&pool.0).await?.parse(); new_channel } @@ -102,12 +103,12 @@ impl Channel { // TODO implement conditional fetching pub async fn fetch_rss( - &self, client: &Client + &self, client: &AdapterClient ) -> Result> { if self.should_skip_fetch() { return Ok(None); } - let bytestream = client.get(self.link.clone()) + let bytestream = client.0.get(self.link.clone()) .send().await? .bytes().await?; @@ -117,7 +118,7 @@ impl Channel { } pub async fn update_metadata( - &self, pool: &SqlitePool, fetched: FetchedRSSChannel + &self, pool: &AdapterPool, fetched: FetchedRSSChannel ) -> Result<()> { let title = fetched.title(); let description = fetched.description(); @@ -130,13 +131,13 @@ impl Channel { WHERE id = ?", title, link, description, fetched_at, self.id.0 - ).execute(pool).await?; + ).execute(&pool.0).await?; Ok(()) } pub async fn update_items( - &self, pool: &SqlitePool, fetched: FetchedRSSChannel + &self, pool: &AdapterPool, fetched: FetchedRSSChannel ) -> Result<()> { let fetched_at = fetched.fetched_at().to_rfc2822(); @@ -151,19 +152,19 @@ impl Channel { VALUES (?, ?, ?, ?, ?, ?)", self.id.0, guid, fetched_at, title, description, content ) - .execute(pool) + .execute(&pool.0) .await?; } Ok(()) } - pub async fn get_items(&self, pool: &SqlitePool) -> Result> { + pub async fn get_items(&self, pool: &AdapterPool) -> Result> { let items: Result> = sqlx::query_as!( UnparsedItem, "SELECT id as `id!` FROM items WHERE channel_id = ?", self.id.0 - ).fetch_all(pool).await?.into_iter().map(UnparsedItem::parse).collect(); + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect(); items } @@ -172,6 +173,7 @@ impl Channel { #[cfg(test)] mod tests { use super::*; + use crate::{Adapter, AdapterBuilder}; use rss::{ Guid as RSSGuid, Item as RSSItem, @@ -179,7 +181,6 @@ mod tests { Channel as RSSChannel, ChannelBuilder as RSSChannelBuilder, }; - use sqlx::SqlitePool; const ITEM_TITLE: &str = "My Item"; const ITEM_GUID1: &str = "https://mycontent.com/blog/1"; @@ -191,18 +192,19 @@ mod tests { const FEED1: &str = "https://example.com/feed"; const FEED2: &str = "https://example2.com/feed"; - async fn setup_test_db() -> SqlitePool { - let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); - sqlx::migrate!().run(&pool).await.unwrap(); - pool + async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() } #[tokio::test] async fn create_channel() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); let url_feed = Url::parse(FEED1).unwrap(); - let channel = Channel::create(&pool, url_feed).await.unwrap(); + let channel = Channel::create(pool, url_feed).await.unwrap(); assert!(channel.id().0 > 0); assert_eq!(channel.link().as_str(), FEED1); @@ -211,11 +213,12 @@ mod tests { #[tokio::test] async fn create_duplicate_returns_existing() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); let url_feed = Url::parse(FEED1).unwrap(); - let channel1 = Channel::create(&pool, url_feed.clone()).await.unwrap(); - let channel2 = Channel::create(&pool, url_feed).await.unwrap(); + let channel1 = Channel::create(pool, url_feed.clone()).await.unwrap(); + let channel2 = Channel::create(pool, url_feed).await.unwrap(); assert_eq!( i64::from(channel1.id()), @@ -225,24 +228,26 @@ mod tests { #[tokio::test] async fn get_all_channels() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); let url_feed1 = Url::parse(FEED1).unwrap(); let url_feed2 = Url::parse(FEED2).unwrap(); - Channel::create(&pool, url_feed1).await.unwrap(); - Channel::create(&pool, url_feed2).await.unwrap(); + Channel::create(pool, url_feed1).await.unwrap(); + Channel::create(pool, url_feed2).await.unwrap(); - let channels = Channel::get_all(&pool).await.unwrap(); + let channels = Channel::get_all(pool).await.unwrap(); assert_eq!(channels.len(), 2); } #[tokio::test] async fn update_metadata() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); let url_feed = Url::parse(FEED1).unwrap(); - let channel = Channel::create(&pool, url_feed).await.unwrap(); + let channel = Channel::create(pool, url_feed).await.unwrap(); let fake_rss: RSSChannel = RSSChannelBuilder::default() .title(CHAN_TITLE) @@ -252,9 +257,9 @@ mod tests { let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); - channel.update_metadata(&pool, fetched).await.unwrap(); + channel.update_metadata(pool, fetched).await.unwrap(); - let updated = Channel::get(&pool, channel.id()).await.unwrap(); + let updated = Channel::get(pool, channel.id()).await.unwrap(); assert_eq!(updated.title(), CHAN_TITLE); assert_eq!(updated.link().as_str(), FEED2); assert_eq!(updated.description(), Some(CHAN_DESC)); @@ -262,10 +267,11 @@ mod tests { #[tokio::test] async fn update_items() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); let url_feed = Url::parse(FEED1).unwrap(); - let channel = Channel::create(&pool, url_feed).await.unwrap(); + let channel = Channel::create(pool, url_feed).await.unwrap(); let item1: RSSItem = RSSItemBuilder::default() .title(ITEM_TITLE.to_string()) @@ -290,18 +296,19 @@ mod tests { let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); - channel.update_items(&pool, fetched).await.unwrap(); + channel.update_items(pool, fetched).await.unwrap(); - let items = channel.get_items(&pool).await.unwrap(); + let items = channel.get_items(pool).await.unwrap(); assert_eq!(items.len(), 2); } #[tokio::test] async fn update_items_ignores_duplicates() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); let url_feed = Url::parse(FEED1).unwrap(); - let channel = Channel::create(&pool, url_feed).await.unwrap(); + let channel = Channel::create(pool, url_feed).await.unwrap(); let item1: RSSItem = RSSItemBuilder::default() .title(ITEM_TITLE.to_string()) @@ -319,12 +326,12 @@ mod tests { let fetched = FetchedRSSChannel::parse(fake_rss.clone()).unwrap(); - channel.update_items(&pool, fetched).await.unwrap(); + channel.update_items(pool, fetched).await.unwrap(); let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); - channel.update_items(&pool, fetched).await.unwrap(); + channel.update_items(pool, fetched).await.unwrap(); - let items = channel.get_items(&pool).await.unwrap(); + let items = channel.get_items(pool).await.unwrap(); assert_eq!(items.len(), 1); } } diff --git a/koucha/src/feed.rs b/koucha/src/feed.rs index 8e33b92..5e8092d 100644 --- a/koucha/src/feed.rs +++ b/koucha/src/feed.rs @@ -1,5 +1,6 @@ use crate::{ Result, + AdapterPool, Item, item::UnparsedItem, Channel, @@ -9,7 +10,6 @@ use crate::{ }, user::UserId, }; -use sqlx::SqlitePool; #[derive(Copy, Clone)] pub struct FeedId(i64); @@ -38,19 +38,19 @@ impl Feed { pub fn title(&self) -> &str { &self.title } pub async fn get( - pool: &SqlitePool, id: FeedId + pool: &AdapterPool, id: FeedId ) -> Result { let feed = sqlx::query_as!( UnparsedFeed, "SELECT id, title FROM feeds WHERE id = ?", id.0 - ).fetch_one(pool).await?.parse(); + ).fetch_one(&pool.0).await?.parse(); feed } pub async fn create( - pool: &SqlitePool, user_id: UserId, title: &str + pool: &AdapterPool, user_id: UserId, title: &str ) -> Result { let int_id = i64::from(user_id); let new_feed = sqlx::query_as!( @@ -59,37 +59,37 @@ impl Feed { VALUES (?, ?) RETURNING id as `id!`, title", int_id, title - ).fetch_one(pool).await?.parse(); + ).fetch_one(&pool.0).await?.parse(); new_feed } pub async fn update_title( - pool: &SqlitePool, id: FeedId, new_title: &str + pool: &AdapterPool, id: FeedId, new_title: &str ) -> Result<()> { sqlx::query!( "UPDATE feeds SET title = ? WHERE id = ?", new_title, id.0 - ).execute(pool).await?; + ).execute(&pool.0).await?; Ok(()) } pub async fn add_channel( - &self, pool: &SqlitePool, channel_id: ChannelId + &self, pool: &AdapterPool, channel_id: ChannelId ) -> Result<()> { let int_channel_id = i64::from(channel_id); sqlx::query!( "INSERT INTO feed_channels (feed_id, channel_id) VALUES (?, ?)", self.id.0, int_channel_id - ).execute(pool).await?; + ).execute(&pool.0).await?; Ok(()) } pub async fn get_items( - &self, pool: &SqlitePool, limit: u8, offset: u32 + &self, pool: &AdapterPool, limit: u8, offset: u32 ) -> Result> { let items: Result> = sqlx::query_as!( UnparsedItem, @@ -98,13 +98,13 @@ impl Feed { ORDER BY score DESC LIMIT ? OFFSET ?", self.id.0, limit, offset - ).fetch_all(pool).await?.into_iter().map(UnparsedItem::parse).collect(); + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect(); items } pub async fn get_channels( - &self, pool: &SqlitePool + &self, pool: &AdapterPool ) -> Result> { let channels: Result> = sqlx::query_as!( UnparsedChannel, @@ -113,7 +113,7 @@ impl Feed { JOIN feed_channels fc on c.id = fc.channel_id WHERE fc.feed_id = ?", self.id.0 - ).fetch_all(pool).await?.into_iter() + ).fetch_all(&pool.0).await?.into_iter() .map(UnparsedChannel::parse).collect(); channels @@ -123,21 +123,21 @@ impl Feed { #[cfg(test)] mod tests { use super::*; - use crate::User; - use sqlx::SqlitePool; + use crate::{User, Adapter, AdapterBuilder}; - async fn setup_test_db() -> SqlitePool { - let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); - sqlx::migrate!().run(&pool).await.unwrap(); - pool + async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() } #[tokio::test] async fn create_feed() { - let pool = setup_test_db().await; - let user = User::create(&pool, "Alice").await.unwrap(); + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, "Alice").await.unwrap(); - let feed = Feed::create(&pool, user.id(), "Tech News").await.unwrap(); + let feed = Feed::create(pool, user.id(), "Tech News").await.unwrap(); assert_eq!(feed.title(), "Tech News"); assert!(feed.id().0 > 0); @@ -145,13 +145,14 @@ mod tests { #[tokio::test] async fn test_update_title() { - let pool = setup_test_db().await; - let user = User::create(&pool, "Alice").await.unwrap(); - let feed = Feed::create(&pool, user.id(), "Tech News").await.unwrap(); + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.id(), "Tech News").await.unwrap(); - Feed::update_title(&pool, feed.id(), "Technology").await.unwrap(); + Feed::update_title(pool, feed.id(), "Technology").await.unwrap(); - let updated = Feed::get(&pool, feed.id()).await.unwrap(); + let updated = Feed::get(pool, feed.id()).await.unwrap(); assert_eq!(updated.title(), "Technology"); } } diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index d12c88e..227939a 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,19 +3,35 @@ use std::error::Error; type Result = std::result::Result>; mod user; -pub use user::User; +pub use user::{ + User, + UserId +}; mod feed; -pub use feed::Feed; +pub use feed::{ + Feed, + FeedId, +}; mod channel; -pub use channel::Channel; +pub use channel::{ + Channel, + ChannelId, + fetch::FetchedRSSChannel, +}; mod item; -pub use item::Item; +pub use item::{ + Item, + ItemId, +}; -pub struct AdapterOptions { +pub struct AdapterPool(sqlx::SqlitePool); +pub struct AdapterClient(reqwest::Client); + +pub struct AdapterBuilder { database_url: String, } -impl AdapterOptions { +impl AdapterBuilder { pub fn new() -> Self { Self { database_url: "sqlite:test.db".to_string(), @@ -30,18 +46,19 @@ impl AdapterOptions { pub async fn create(self) -> Result { let db = sqlx::sqlite::SqlitePoolOptions::new() .connect(&self.database_url).await?; + sqlx::migrate!().run(&db).await?; let client = reqwest::Client::new(); - Ok(Adapter { db, client }) + Ok(Adapter { db: AdapterPool(db), client: AdapterClient(client) }) } } pub struct Adapter { - db: sqlx::SqlitePool, - client: reqwest::Client, + db: AdapterPool, + client: AdapterClient, } impl Adapter { - pub fn get_pool(&self) -> &sqlx::SqlitePool { &self.db } - pub fn get_client(&self) -> &reqwest::Client { &self.client } + pub fn get_pool(&self) -> &AdapterPool { &self.db } + pub fn get_client(&self) -> &AdapterClient { &self.client } } diff --git a/koucha/src/user.rs b/koucha/src/user.rs index fc4e6ad..c8ea50b 100644 --- a/koucha/src/user.rs +++ b/koucha/src/user.rs @@ -1,6 +1,6 @@ -use sqlx::SqlitePool; use crate::{ Result, + AdapterPool, Feed, feed::UnparsedFeed, }; @@ -31,31 +31,31 @@ impl User { pub fn id(&self) -> UserId { self.id } pub fn name(&self) -> &str { &self.name } - pub async fn get(pool: &SqlitePool, id: UserId) -> Result { + pub async fn get(pool: &AdapterPool, id: UserId) -> Result { let user = sqlx::query_as!( UnparsedUser, "SELECT id, name FROM users WHERE id = ?", id.0 - ).fetch_one(pool).await?.parse(); + ).fetch_one(&pool.0).await?.parse(); user } - pub async fn get_all(pool: &SqlitePool) -> Result> { + pub async fn get_all(pool: &AdapterPool) -> Result> { let users: Result> = sqlx::query_as!( UnparsedUser, "SELECT id, name FROM users" - ).fetch_all(pool).await?.into_iter().map(UnparsedUser::parse).collect(); + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedUser::parse).collect(); users } - pub async fn create(pool: &SqlitePool, name: &str) -> Result { + pub async fn create(pool: &AdapterPool, name: &str) -> Result { let result = sqlx::query!( "INSERT INTO users (name) VALUES (?) RETURNING id, name", name - ).fetch_one(pool).await?; + ).fetch_one(&pool.0).await?; Ok(Self { id: UserId(result.id), @@ -64,22 +64,22 @@ impl User { } pub async fn update_name( - pool: &SqlitePool, id: UserId, new_name: &str + pool: &AdapterPool, id: UserId, new_name: &str ) -> Result<()> { sqlx::query!( "UPDATE users SET name = ? WHERE id = ?", new_name, id.0 - ).execute(pool).await?; + ).execute(&pool.0).await?; Ok(()) } - pub async fn get_feeds(&self, pool: &SqlitePool) -> Result> { + pub async fn get_feeds(&self, pool: &AdapterPool) -> Result> { let feeds: Result> = sqlx::query_as!( UnparsedFeed, "SELECT id, title FROM feeds WHERE user_id = ?", self.id.0 - ).fetch_all(pool).await?.into_iter() + ).fetch_all(&pool.0).await?.into_iter() .map(UnparsedFeed::parse).collect(); feeds @@ -89,30 +89,32 @@ impl User { #[cfg(test)] mod tests { use super::*; - use sqlx::SqlitePool; + use crate::{AdapterBuilder, Adapter}; - async fn setup_test_db() -> SqlitePool { - let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); - sqlx::migrate!().run(&pool).await.unwrap(); - pool + async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() } #[tokio::test] async fn get_user() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - let new_user = User::create(&pool, "Alice").await.unwrap(); + let new_user = User::create(pool, "Alice").await.unwrap(); - let fetched_user = User::get(&pool, new_user.id).await.unwrap(); + let fetched_user = User::get(pool, new_user.id).await.unwrap(); assert_eq!(fetched_user.name, "Alice"); assert!(fetched_user.id.0 > 0); } #[tokio::test] async fn create_user() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - let user = User::create(&pool, "Alice").await.unwrap(); + let user = User::create(pool, "Alice").await.unwrap(); assert_eq!(user.name, "Alice"); assert!(user.id.0 > 0); @@ -120,22 +122,24 @@ mod tests { #[tokio::test] async fn create_duplicate_user() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - let _user = User::create(&pool, "Alice").await.unwrap(); - let duplicate_user = User::create(&pool, "Alice").await; + let _user = User::create(pool, "Alice").await.unwrap(); + let duplicate_user = User::create(pool, "Alice").await; assert!(duplicate_user.is_err()); } #[tokio::test] async fn get_all_users() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - User::create(&pool, "Alice").await.unwrap(); - User::create(&pool, "Bob").await.unwrap(); + User::create(pool, "Alice").await.unwrap(); + User::create(pool, "Bob").await.unwrap(); - let users = User::get_all(&pool).await.unwrap(); + let users = User::get_all(pool).await.unwrap(); assert_eq!(users.len(), 2); assert!(users.iter().any(|u| u.name == "Alice")); @@ -144,32 +148,35 @@ mod tests { #[tokio::test] async fn update_name() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - let user = User::create(&pool, "Alice").await.unwrap(); - User::update_name(&pool, user.id, "Alicia").await.unwrap(); + let user = User::create(pool, "Alice").await.unwrap(); + User::update_name(pool, user.id, "Alicia").await.unwrap(); - let updated = User::get(&pool, user.id).await.unwrap(); + let updated = User::get(pool, user.id).await.unwrap(); assert_eq!(updated.name, "Alicia"); } #[tokio::test] async fn update_name_to_duplicate() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - let alice = User::create(&pool, "Alice").await.unwrap(); - let _sam = User::create(&pool, "Sam").await.unwrap(); - let status = User::update_name(&pool, alice.id, "Sam").await; + let alice = User::create(pool, "Alice").await.unwrap(); + let _sam = User::create(pool, "Sam").await.unwrap(); + let status = User::update_name(pool, alice.id, "Sam").await; assert!(status.is_err()); } #[tokio::test] async fn get_feeds_empty() { - let pool = setup_test_db().await; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); - let user = User::create(&pool, "Alice").await.unwrap(); - let feeds = user.get_feeds(&pool).await.unwrap(); + let user = User::create(pool, "Alice").await.unwrap(); + let feeds = user.get_feeds(pool).await.unwrap(); assert_eq!(feeds.len(), 0); } From 3748606e216936395c1f5e2ba26dd67fb34c8f23 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 22 Jan 2026 13:49:49 -0800 Subject: [PATCH 13/32] Move to DB module for visibility; separate db and client code --- koucha/src/channel.rs | 337 ------------------------------ koucha/src/db.rs | 22 ++ koucha/src/db/channel.rs | 204 ++++++++++++++++++ koucha/src/{ => db}/feed.rs | 30 +-- koucha/src/db/item.rs | 68 ++++++ koucha/src/{ => db}/user.rs | 11 +- koucha/src/{channel => }/fetch.rs | 24 ++- koucha/src/item.rs | 20 -- koucha/src/lib.rs | 23 +- 9 files changed, 340 insertions(+), 399 deletions(-) delete mode 100644 koucha/src/channel.rs create mode 100644 koucha/src/db.rs create mode 100644 koucha/src/db/channel.rs rename koucha/src/{ => db}/feed.rs (90%) create mode 100644 koucha/src/db/item.rs rename koucha/src/{ => db}/user.rs (96%) rename koucha/src/{channel => }/fetch.rs (78%) delete mode 100644 koucha/src/item.rs diff --git a/koucha/src/channel.rs b/koucha/src/channel.rs deleted file mode 100644 index da61531..0000000 --- a/koucha/src/channel.rs +++ /dev/null @@ -1,337 +0,0 @@ -use reqwest::Url; -use chrono::{DateTime, Utc}; -use crate::{ - Result, - AdapterPool, - AdapterClient, - Item, - channel::fetch::FetchedRSSChannel, - item::UnparsedItem, -}; - -#[derive(Copy, Clone)] -pub struct ChannelId(i64); -impl From for i64 { fn from(id: ChannelId) -> Self { id.0 } } - -pub mod fetch; - -pub struct UnparsedChannel { - pub id: i64, - pub title: String, - pub link: String, - pub description: Option, - pub last_fetched: Option, -} -impl UnparsedChannel { - pub fn parse(self) -> Result { - Ok(Channel { - id: ChannelId(self.id), - title: self.title, - link: Url::parse(&self.link)?, - description: self.description, - last_fetched: self.last_fetched.as_deref() - .map(DateTime::parse_from_rfc2822) - .transpose()? - .map(|dt| dt.with_timezone(&Utc)), - }) - } -} - -pub struct Channel { - id: ChannelId, - title: String, - link: Url, - description: Option, - last_fetched: Option>, -} - -impl Channel { - pub fn id(&self) -> ChannelId { self.id } - pub fn title(&self) -> &str { &self.title } - pub fn link(&self) -> &Url { &self.link } - pub fn description(&self) -> Option<&str> { self.description.as_deref() } - - pub async fn get_all(pool: &AdapterPool) -> Result> { - let channels: Result> = sqlx::query_as!( - UnparsedChannel, - "SELECT id, title, link, description, last_fetched FROM channels" - ).fetch_all(&pool.0).await?.into_iter().map(UnparsedChannel::parse).collect(); - - channels - } - - pub async fn get(pool: &AdapterPool, id: ChannelId) -> Result { - let channel: Result = sqlx::query_as!( - UnparsedChannel, - "SELECT id, title, link, description, last_fetched - FROM channels - WHERE id = ?", - id.0 - ).fetch_one(&pool.0).await?.parse(); - - channel - } - - pub async fn create( - pool: &AdapterPool, link: Url - ) -> Result { - let link_str = link.as_str(); - - if let Ok(existing_channel) = sqlx::query_as!( - UnparsedChannel, - "SELECT id as `id!`, title, link, description, last_fetched - FROM channels - WHERE link = ?", - link_str - ).fetch_one(&pool.0).await { - return existing_channel.parse(); - } - - let new_channel = sqlx::query_as!( - UnparsedChannel, - "INSERT INTO channels (title, link) - VALUES (?, ?) - RETURNING id, title, link, description, last_fetched", - link_str, link_str - ).fetch_one(&pool.0).await?.parse(); - - new_channel - } - - // TODO implement fetch skipping - fn should_skip_fetch(&self) -> bool { false } - - // TODO implement conditional fetching - pub async fn fetch_rss( - &self, client: &AdapterClient - ) -> Result> { - if self.should_skip_fetch() { - return Ok(None); - } - let bytestream = client.0.get(self.link.clone()) - .send().await? - .bytes().await?; - - let rss_channel = rss::Channel::read_from(&bytestream[..])?; - - Ok(Some(FetchedRSSChannel::parse(rss_channel)?)) - } - - pub async fn update_metadata( - &self, pool: &AdapterPool, fetched: FetchedRSSChannel - ) -> Result<()> { - let title = fetched.title(); - let description = fetched.description(); - let link = fetched.link().as_str(); - let fetched_at = fetched.fetched_at().to_rfc2822(); - sqlx::query!( - "UPDATE channels - SET title = ?, link = ?, description = ?, - last_fetched = ? - WHERE id = ?", - title, link, description, fetched_at, - self.id.0 - ).execute(&pool.0).await?; - - Ok(()) - } - - pub async fn update_items( - &self, pool: &AdapterPool, fetched: FetchedRSSChannel - ) -> Result<()> { - let fetched_at = fetched.fetched_at().to_rfc2822(); - - for item in fetched.items() { - let guid = item.guid(); - let title = item.title(); - let description = item.description(); - let content = item.content(); - sqlx::query!( - "INSERT OR IGNORE INTO items - (channel_id, guid, fetched_at, title, description, content) - VALUES (?, ?, ?, ?, ?, ?)", - self.id.0, guid, fetched_at, title, description, content - ) - .execute(&pool.0) - .await?; - } - - Ok(()) - } - - pub async fn get_items(&self, pool: &AdapterPool) -> Result> { - let items: Result> = sqlx::query_as!( - UnparsedItem, - "SELECT id as `id!` FROM items WHERE channel_id = ?", - self.id.0 - ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect(); - - items - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::{Adapter, AdapterBuilder}; - use rss::{ - Guid as RSSGuid, - Item as RSSItem, - ItemBuilder as RSSItemBuilder, - Channel as RSSChannel, - ChannelBuilder as RSSChannelBuilder, - }; - - const ITEM_TITLE: &str = "My Item"; - const ITEM_GUID1: &str = "https://mycontent.com/blog/1"; - const ITEM_GUID2: &str = "something-else!"; - const ITEM_DESC: &str = "A test item"; - const ITEM_CONT: &str = "some rss content baby"; - const CHAN_TITLE: &str = "My Feed"; - const CHAN_DESC: &str = "A test feed"; - const FEED1: &str = "https://example.com/feed"; - const FEED2: &str = "https://example2.com/feed"; - - async fn setup_adapter() -> Adapter { - AdapterBuilder::new() - .database_url("sqlite::memory:") - .create().await.unwrap() - } - - #[tokio::test] - async fn create_channel() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - let url_feed = Url::parse(FEED1).unwrap(); - - let channel = Channel::create(pool, url_feed).await.unwrap(); - - assert!(channel.id().0 > 0); - assert_eq!(channel.link().as_str(), FEED1); - assert!(channel.title().len() > 0); - } - - #[tokio::test] - async fn create_duplicate_returns_existing() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - let url_feed = Url::parse(FEED1).unwrap(); - - let channel1 = Channel::create(pool, url_feed.clone()).await.unwrap(); - let channel2 = Channel::create(pool, url_feed).await.unwrap(); - - assert_eq!( - i64::from(channel1.id()), - i64::from(channel2.id()) - ); - } - - #[tokio::test] - async fn get_all_channels() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - let url_feed1 = Url::parse(FEED1).unwrap(); - let url_feed2 = Url::parse(FEED2).unwrap(); - - Channel::create(pool, url_feed1).await.unwrap(); - Channel::create(pool, url_feed2).await.unwrap(); - - let channels = Channel::get_all(pool).await.unwrap(); - - assert_eq!(channels.len(), 2); - } - - #[tokio::test] - async fn update_metadata() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - let url_feed = Url::parse(FEED1).unwrap(); - - let channel = Channel::create(pool, url_feed).await.unwrap(); - - let fake_rss: RSSChannel = RSSChannelBuilder::default() - .title(CHAN_TITLE) - .link(FEED2) - .description(CHAN_DESC) - .build(); - - let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); - - channel.update_metadata(pool, fetched).await.unwrap(); - - let updated = Channel::get(pool, channel.id()).await.unwrap(); - assert_eq!(updated.title(), CHAN_TITLE); - assert_eq!(updated.link().as_str(), FEED2); - assert_eq!(updated.description(), Some(CHAN_DESC)); - } - - #[tokio::test] - async fn update_items() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - let url_feed = Url::parse(FEED1).unwrap(); - - let channel = Channel::create(pool, url_feed).await.unwrap(); - - let item1: RSSItem = RSSItemBuilder::default() - .title(ITEM_TITLE.to_string()) - .description(ITEM_DESC.to_string()) - .content(ITEM_CONT.to_string()) - .guid(RSSGuid { value: ITEM_GUID1.to_string(), permalink: false }) - .build(); - let item2: RSSItem = RSSItemBuilder::default() - .title(ITEM_TITLE.to_string()) - .description(ITEM_DESC.to_string()) - .content(ITEM_CONT.to_string()) - .guid(RSSGuid { value: ITEM_GUID2.to_string(), permalink: false }) - .build(); - - let fake_rss: RSSChannel = RSSChannelBuilder::default() - .title(CHAN_TITLE) - .link(FEED2) - .description(CHAN_DESC) - .item(item1) - .item(item2) - .build(); - - let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); - - channel.update_items(pool, fetched).await.unwrap(); - - let items = channel.get_items(pool).await.unwrap(); - assert_eq!(items.len(), 2); - } - - #[tokio::test] - async fn update_items_ignores_duplicates() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - let url_feed = Url::parse(FEED1).unwrap(); - - let channel = Channel::create(pool, url_feed).await.unwrap(); - - let item1: RSSItem = RSSItemBuilder::default() - .title(ITEM_TITLE.to_string()) - .description(ITEM_DESC.to_string()) - .content(ITEM_CONT.to_string()) - .guid(RSSGuid { value: ITEM_GUID1.to_string(), permalink: false }) - .build(); - - let fake_rss: RSSChannel = RSSChannelBuilder::default() - .title(CHAN_TITLE) - .link(FEED2) - .description(CHAN_DESC) - .item(item1) - .build(); - - let fetched = FetchedRSSChannel::parse(fake_rss.clone()).unwrap(); - - channel.update_items(pool, fetched).await.unwrap(); - let fetched = FetchedRSSChannel::parse(fake_rss).unwrap(); - - channel.update_items(pool, fetched).await.unwrap(); - - let items = channel.get_items(pool).await.unwrap(); - assert_eq!(items.len(), 1); - } -} diff --git a/koucha/src/db.rs b/koucha/src/db.rs new file mode 100644 index 0000000..f5e1372 --- /dev/null +++ b/koucha/src/db.rs @@ -0,0 +1,22 @@ +mod user; +pub use user::User; +mod feed; +pub use feed::Feed; +mod channel; +pub use channel::Channel; +mod item; +pub use item::Item; + + +macro_rules! define_id { + ($name:ident) => { + #[derive(Copy, Clone)] + pub struct $name(i64); + impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } + }; +} + +define_id!(UserId); +define_id!(FeedId); +define_id!(ChannelId); +define_id!(ItemId); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs new file mode 100644 index 0000000..931eb3d --- /dev/null +++ b/koucha/src/db/channel.rs @@ -0,0 +1,204 @@ +use reqwest::Url; +use chrono::{DateTime, Utc}; +use crate::{ + Result, + AdapterPool, + db::{ + ChannelId, + Item, + item::UnparsedItem, + }, + fetch::FetchedRSSChannel, +}; + +pub struct UnparsedChannel { + pub id: i64, + pub title: String, + pub link: String, + pub description: Option, + pub last_fetched: Option, +} +impl UnparsedChannel { + pub fn parse(self) -> Result { + Ok(Channel { + id: ChannelId(self.id), + title: self.title, + link: Url::parse(&self.link)?, + description: self.description, + last_fetched: self.last_fetched.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), + }) + } +} + +pub struct Channel { + id: ChannelId, + title: String, + link: Url, + description: Option, + last_fetched: Option>, +} + +impl Channel { + pub fn id(&self) -> ChannelId { self.id } + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } + pub fn last_fetched(&self) -> Option> { self.last_fetched } + + pub async fn get_all(pool: &AdapterPool) -> Result> { + let channels: Result> = sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched FROM channels" + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedChannel::parse).collect(); + + channels + } + + pub async fn get(pool: &AdapterPool, id: ChannelId) -> Result { + let channel: Result = sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched + FROM channels + WHERE id = ?", + id.0 + ).fetch_one(&pool.0).await?.parse(); + + channel + } + + pub async fn get_or_create( + pool: &AdapterPool, link: Url + ) -> Result { + let link_str = link.as_str(); + + let channel = sqlx::query_as!( + UnparsedChannel, + "INSERT INTO channels (title, link) + VALUES(?, ?) + ON CONFLICT(link) DO UPDATE SET link = link + RETURNING id, title, link, description, last_fetched", + link_str, link_str // We use the url as a placeholder title + ).fetch_one(&pool.0).await?.parse(); + + channel + } + + // TODO implement fetch skipping + pub fn should_skip_fetch(&self) -> bool { false } + + pub async fn update_metadata( + &self, pool: &AdapterPool, fetched: FetchedRSSChannel + ) -> Result<()> { + let title = fetched.title(); + let description = fetched.description(); + let link = fetched.link().as_str(); + let fetched_at = fetched.fetched_at().to_rfc2822(); + sqlx::query!( + "UPDATE channels + SET title = ?, link = ?, description = ?, + last_fetched = ? + WHERE id = ?", + title, link, description, fetched_at, + self.id.0 + ).execute(&pool.0).await?; + + Ok(()) + } + + pub async fn update_items( + &self, pool: &AdapterPool, fetched: FetchedRSSChannel + ) -> Result<()> { + let fetched_at = fetched.fetched_at().to_rfc2822(); + + for item in fetched.items() { + let guid = item.guid(); + let title = item.title(); + let description = item.description(); + let content = item.content(); + sqlx::query!( + "INSERT OR IGNORE INTO items + (channel_id, guid, fetched_at, title, description, content) + VALUES (?, ?, ?, ?, ?, ?)", + self.id.0, guid, fetched_at, title, description, content + ) + .execute(&pool.0) + .await?; + } + + Ok(()) + } + + pub async fn get_items(&self, pool: &AdapterPool) -> Result> { + let items: Result> = sqlx::query_as!( + UnparsedItem, + "SELECT id as `id!`, channel_id, guid, fetched_at, title, description, + content + FROM items + WHERE channel_id = ?", + self.id.0 + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect(); + + items + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{Adapter, AdapterBuilder}; + + const FEED1: &str = "https://example.com/feed"; + const FEED2: &str = "https://example2.com/feed"; + + async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() + } + + #[tokio::test] + async fn create_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::get_or_create(pool, url_feed).await.unwrap(); + + assert!(channel.id().0 > 0); + assert_eq!(channel.link().as_str(), FEED1); + assert!(channel.title().len() > 0); + } + + #[tokio::test] + async fn create_duplicate_returns_existing() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed = Url::parse(FEED1).unwrap(); + + let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap(); + let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap(); + + assert_eq!( + i64::from(channel1.id()), + i64::from(channel2.id()) + ); + } + + #[tokio::test] + async fn get_all_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed1 = Url::parse(FEED1).unwrap(); + let url_feed2 = Url::parse(FEED2).unwrap(); + + Channel::get_or_create(pool, url_feed1).await.unwrap(); + Channel::get_or_create(pool, url_feed2).await.unwrap(); + + let channels = Channel::get_all(pool).await.unwrap(); + + assert_eq!(channels.len(), 2); + } +} diff --git a/koucha/src/feed.rs b/koucha/src/db/feed.rs similarity index 90% rename from koucha/src/feed.rs rename to koucha/src/db/feed.rs index 5e8092d..1d081e6 100644 --- a/koucha/src/feed.rs +++ b/koucha/src/db/feed.rs @@ -1,20 +1,17 @@ use crate::{ - Result, AdapterPool, - Item, - item::UnparsedItem, - Channel, - channel::{ - UnparsedChannel, + Result, + db::{ + Channel, ChannelId, + FeedId, + Item, + UserId, + channel::UnparsedChannel, + item::UnparsedItem, }, - user::UserId, }; -#[derive(Copy, Clone)] -pub struct FeedId(i64); -impl From for i64 { fn from(id: FeedId) -> Self { id.0 } } - pub struct UnparsedFeed { pub id: i64, pub title: String, @@ -93,7 +90,10 @@ impl Feed { ) -> Result> { let items: Result> = sqlx::query_as!( UnparsedItem, - "SELECT item_id as id FROM feed_items + "SELECT i.id as `id!`, i.channel_id, i.guid, i.fetched_at, i.title, + i.description, i.content + FROM items i + JOIN feed_items fi on i.id = fi.item_id WHERE feed_id = ? AND archived = FALSE ORDER BY score DESC LIMIT ? OFFSET ?", @@ -123,7 +123,11 @@ impl Feed { #[cfg(test)] mod tests { use super::*; - use crate::{User, Adapter, AdapterBuilder}; + use crate::{ + Adapter, + AdapterBuilder, + db::User, + }; async fn setup_adapter() -> Adapter { AdapterBuilder::new() diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs new file mode 100644 index 0000000..62fa919 --- /dev/null +++ b/koucha/src/db/item.rs @@ -0,0 +1,68 @@ +use crate::{ + Result, + AdapterPool, + db::{ + ChannelId, + ItemId, + } +}; +use chrono::{DateTime, Utc}; + +pub struct UnparsedItem { + pub id: i64, + pub channel_id: i64, + pub guid: String, + pub fetched_at: String, + + pub title: Option, + pub description: Option, + pub content: Option, +} + +impl UnparsedItem { + pub fn parse(self) -> Result { + Ok(Item { + id: ItemId(self.id), + channel_id: ChannelId(self.channel_id), + guid: self.guid, + fetched_at: DateTime::parse_from_rfc2822(&self.fetched_at)?.with_timezone(&Utc), + + title: self.title, + description: self.description, + content: self.content, + }) + } +} + +pub struct Item { + id: ItemId, + channel_id: ChannelId, + guid: String, + fetched_at: DateTime, + + title: Option, + description: Option, + content: Option, +} + +impl Item { + pub async fn get_or_create( + pool: &AdapterPool, from_channel: ChannelId, guid: &str, + fetched_at: DateTime + ) -> Result { + let int_channel_id = i64::from(from_channel); + let last_fetched = fetched_at.to_rfc2822(); + + let item = sqlx::query_as!( + UnparsedItem, + "INSERT INTO items (channel_id, guid, fetched_at) + VALUES(?, ?, ?) + ON CONFLICT(id) DO UPDATE SET id = id + RETURNING id as `id!`, channel_id, guid, fetched_at, title, description, + content", + int_channel_id, guid, last_fetched + ).fetch_one(&pool.0).await?.parse(); + + item + } +} diff --git a/koucha/src/user.rs b/koucha/src/db/user.rs similarity index 96% rename from koucha/src/user.rs rename to koucha/src/db/user.rs index c8ea50b..05b7a4b 100644 --- a/koucha/src/user.rs +++ b/koucha/src/db/user.rs @@ -1,14 +1,13 @@ use crate::{ Result, AdapterPool, - Feed, - feed::UnparsedFeed, + db::{ + UserId, + Feed, + feed::UnparsedFeed, + }, }; -#[derive(Copy, Clone)] -pub struct UserId(i64); -impl From for i64 { fn from(id: UserId) -> Self { id.0 } } - pub struct UnparsedUser { pub id: i64, pub name: String, diff --git a/koucha/src/channel/fetch.rs b/koucha/src/fetch.rs similarity index 78% rename from koucha/src/channel/fetch.rs rename to koucha/src/fetch.rs index b660cfe..b71b30c 100644 --- a/koucha/src/channel/fetch.rs +++ b/koucha/src/fetch.rs @@ -1,4 +1,8 @@ -use crate::Result; +use crate::{ + Result, + db::Channel, + AdapterClient, +}; use reqwest::Url; use chrono::{DateTime, Utc}; use std::hash::{Hash, Hasher}; @@ -53,7 +57,23 @@ impl FetchedRSSChannel { pub fn items(&self) -> &[FetchedRSSItem] { &self.items } pub fn fetched_at(&self) -> &DateTime { &self.fetched_at } - pub fn parse(rss: rss::Channel) -> Result { + pub async fn fetch_channel( + client: &AdapterClient, channel: Channel + ) -> Result> { + if channel.should_skip_fetch() { + return Ok(None); + } + + let bytestream = client.0.get(channel.link().clone()) + .send().await? + .bytes().await?; + + let rss_channel = rss::Channel::read_from(&bytestream[..])?; + + Ok(Some(FetchedRSSChannel::parse(rss_channel)?)) + } + + fn parse(rss: rss::Channel) -> Result { Ok(FetchedRSSChannel { title: rss.title, link: Url::parse(&rss.link)?, diff --git a/koucha/src/item.rs b/koucha/src/item.rs deleted file mode 100644 index 4d6af9f..0000000 --- a/koucha/src/item.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::Result; - -#[derive(Copy, Clone)] -pub struct ItemId(i64); -impl From for i64 { fn from(id: ItemId) -> Self { id.0 } } - -pub struct UnparsedItem { - pub id: i64, -} -impl UnparsedItem { - pub fn parse(self) -> Result { - Ok(Item { - id: ItemId(self.id), - }) - } -} - -pub struct Item { - id: ItemId, -} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 227939a..1e29303 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -2,27 +2,8 @@ use std::error::Error; type Result = std::result::Result>; -mod user; -pub use user::{ - User, - UserId -}; -mod feed; -pub use feed::{ - Feed, - FeedId, -}; -mod channel; -pub use channel::{ - Channel, - ChannelId, - fetch::FetchedRSSChannel, -}; -mod item; -pub use item::{ - Item, - ItemId, -}; +pub mod db; +pub mod fetch; pub struct AdapterPool(sqlx::SqlitePool); pub struct AdapterClient(reqwest::Client); From 0bb9a81d606b33271d7c42411eb85478f7d2bc82 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 22 Jan 2026 15:55:31 -0800 Subject: [PATCH 14/32] clean up 'update_items' --- .../20260115003047_initial_schema.sql | 2 +- koucha/src/db/channel.rs | 77 +++++++++++++++---- koucha/src/db/feed.rs | 4 +- koucha/src/db/item.rs | 55 +++++++++---- 4 files changed, 104 insertions(+), 34 deletions(-) diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql index 25122e7..63d3591 100644 --- a/koucha/migrations/20260115003047_initial_schema.sql +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -19,8 +19,8 @@ CREATE TABLE items ( id INTEGER PRIMARY KEY, channel_id INTEGER NOT NULL, guid TEXT NOT NULL, - fetched_at TEXT NOT NULL, + fetched_at TEXT, title TEXT, description TEXT, content TEXT, diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 931eb3d..c837475 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -6,6 +6,7 @@ use crate::{ db::{ ChannelId, Item, + FeedId, item::UnparsedItem, }, fetch::FetchedRSSChannel, @@ -33,6 +34,40 @@ impl UnparsedChannel { } } +pub struct UnparsedFeedChannel { + pub channel_id: i64, + pub feed_id: i64, +} +impl UnparsedFeedChannel { + pub fn parse(self) -> Result { + Ok(FeedChannel { + channel_id: ChannelId(self.channel_id), + feed_id: FeedId(self.feed_id) + }) + } +} + +pub struct FeedChannel { + channel_id: ChannelId, + feed_id: FeedId, +} + +impl FeedChannel { + pub async fn add_item( + &self, pool: &AdapterPool, item: &Item + ) -> Result<()> { + let int_item_id = i64::from(item.id()); + let int_feed_id = i64::from(self.feed_id); + + sqlx::query!( + "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score) + VALUES (?, ?, 5)", // TODO: Add in scoring featuress + int_feed_id, int_item_id + ).execute(&pool.0).await?; + Ok(()) + } +} + pub struct Channel { id: ChannelId, title: String, @@ -108,24 +143,34 @@ impl Channel { Ok(()) } + async fn get_feed_channels( + &self, pool: &AdapterPool + ) -> Result> { + let feeds: Result> = sqlx::query_as!( + UnparsedFeedChannel, + "SELECT channel_id, feed_id + FROM feed_channels + WHERE channel_id = ?", + self.id.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedFeedChannel::parse).collect(); + + feeds + } + pub async fn update_items( &self, pool: &AdapterPool, fetched: FetchedRSSChannel ) -> Result<()> { - let fetched_at = fetched.fetched_at().to_rfc2822(); + let fetched_at = fetched.fetched_at(); - for item in fetched.items() { - let guid = item.guid(); - let title = item.title(); - let description = item.description(); - let content = item.content(); - sqlx::query!( - "INSERT OR IGNORE INTO items - (channel_id, guid, fetched_at, title, description, content) - VALUES (?, ?, ?, ?, ?, ?)", - self.id.0, guid, fetched_at, title, description, content - ) - .execute(&pool.0) - .await?; + let feed_channels = self.get_feed_channels(pool).await?; + + for rss_item in fetched.items() { + let new_item = Item::get_or_create(pool, self.id, rss_item.guid()).await?; + new_item.update_content(pool, rss_item, &fetched_at).await?; + for feed_channel in &feed_channels { + feed_channel.add_item(pool, &new_item).await?; + } } Ok(()) @@ -134,9 +179,9 @@ impl Channel { pub async fn get_items(&self, pool: &AdapterPool) -> Result> { let items: Result> = sqlx::query_as!( UnparsedItem, - "SELECT id as `id!`, channel_id, guid, fetched_at, title, description, + "SELECT id as `id!`, channel_id, fetched_at, title, description, content - FROM items + FROM items WHERE channel_id = ?", self.id.0 ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect(); diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index 1d081e6..bb4783d 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -90,8 +90,8 @@ impl Feed { ) -> Result> { let items: Result> = sqlx::query_as!( UnparsedItem, - "SELECT i.id as `id!`, i.channel_id, i.guid, i.fetched_at, i.title, - i.description, i.content + "SELECT i.id as `id!`, i.channel_id, i.fetched_at, i.title, i.description, + i.content FROM items i JOIN feed_items fi on i.id = fi.item_id WHERE feed_id = ? AND archived = FALSE diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs index 62fa919..1cc7f6c 100644 --- a/koucha/src/db/item.rs +++ b/koucha/src/db/item.rs @@ -4,16 +4,16 @@ use crate::{ db::{ ChannelId, ItemId, - } + }, + fetch::FetchedRSSItem, }; use chrono::{DateTime, Utc}; pub struct UnparsedItem { pub id: i64, pub channel_id: i64, - pub guid: String, - pub fetched_at: String, - + pub fetched_at: Option, + pub title: Option, pub description: Option, pub content: Option, @@ -24,8 +24,10 @@ impl UnparsedItem { Ok(Item { id: ItemId(self.id), channel_id: ChannelId(self.channel_id), - guid: self.guid, - fetched_at: DateTime::parse_from_rfc2822(&self.fetched_at)?.with_timezone(&Utc), + fetched_at: self.fetched_at.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), title: self.title, description: self.description, @@ -37,32 +39,55 @@ impl UnparsedItem { pub struct Item { id: ItemId, channel_id: ChannelId, - guid: String, - fetched_at: DateTime, + fetched_at: Option>, title: Option, description: Option, content: Option, } impl Item { + pub fn id(&self) -> ItemId { self.id } + pub fn channel(&self) -> ChannelId { self.channel_id } + pub fn title(&self) -> Option<&str> { self.title.as_deref() } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } + pub fn content(&self) -> Option<&str> { self.content.as_deref() } + pub async fn get_or_create( - pool: &AdapterPool, from_channel: ChannelId, guid: &str, - fetched_at: DateTime + pool: &AdapterPool, from_channel: ChannelId, guid: &str ) -> Result { let int_channel_id = i64::from(from_channel); - let last_fetched = fetched_at.to_rfc2822(); let item = sqlx::query_as!( UnparsedItem, - "INSERT INTO items (channel_id, guid, fetched_at) - VALUES(?, ?, ?) + "INSERT INTO items (channel_id, guid) + VALUES(?, ?) ON CONFLICT(id) DO UPDATE SET id = id - RETURNING id as `id!`, channel_id, guid, fetched_at, title, description, + RETURNING id as `id!`, channel_id, fetched_at, title, description, content", - int_channel_id, guid, last_fetched + int_channel_id, guid ).fetch_one(&pool.0).await?.parse(); item } + + pub async fn update_content( + &self, pool: &AdapterPool, fetched: &FetchedRSSItem, fetched_at: &DateTime + ) -> Result<()> { + let title = fetched.title(); + let description = fetched.description(); + let content = fetched.content(); + let string_fetched_at = fetched_at.to_rfc2822(); + + sqlx::query!( + "UPDATE items + SET title = ?, description = ?, content = ?, + fetched_at = ? + WHERE id = ?", + title, description, content, string_fetched_at, + self.id.0 + ).execute(&pool.0).await?; + + Ok(()) + } } From 0639c5ca12424b743e739b5c68498cca0a7b1154 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 23 Jan 2026 16:35:43 -0800 Subject: [PATCH 15/32] Pull out feed_channel, add more tests --- koucha/src/db.rs | 4 +- koucha/src/db/channel.rs | 37 +--------- koucha/src/db/feed_channel.rs | 131 ++++++++++++++++++++++++++++++++++ koucha/src/db/item.rs | 54 ++++++++++++-- 4 files changed, 184 insertions(+), 42 deletions(-) create mode 100644 koucha/src/db/feed_channel.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs index f5e1372..79eaf50 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -2,6 +2,8 @@ mod user; pub use user::User; mod feed; pub use feed::Feed; +mod feed_channel; +pub use feed_channel::FeedChannel; mod channel; pub use channel::Channel; mod item; @@ -10,7 +12,7 @@ pub use item::Item; macro_rules! define_id { ($name:ident) => { - #[derive(Copy, Clone)] + #[derive(PartialEq, Debug, Copy, Clone)] pub struct $name(i64); impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } }; diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index c837475..22bea40 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -6,7 +6,8 @@ use crate::{ db::{ ChannelId, Item, - FeedId, + FeedChannel, + feed_channel::UnparsedFeedChannel, item::UnparsedItem, }, fetch::FetchedRSSChannel, @@ -34,40 +35,6 @@ impl UnparsedChannel { } } -pub struct UnparsedFeedChannel { - pub channel_id: i64, - pub feed_id: i64, -} -impl UnparsedFeedChannel { - pub fn parse(self) -> Result { - Ok(FeedChannel { - channel_id: ChannelId(self.channel_id), - feed_id: FeedId(self.feed_id) - }) - } -} - -pub struct FeedChannel { - channel_id: ChannelId, - feed_id: FeedId, -} - -impl FeedChannel { - pub async fn add_item( - &self, pool: &AdapterPool, item: &Item - ) -> Result<()> { - let int_item_id = i64::from(item.id()); - let int_feed_id = i64::from(self.feed_id); - - sqlx::query!( - "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score) - VALUES (?, ?, 5)", // TODO: Add in scoring featuress - int_feed_id, int_item_id - ).execute(&pool.0).await?; - Ok(()) - } -} - pub struct Channel { id: ChannelId, title: String, diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs new file mode 100644 index 0000000..4421b88 --- /dev/null +++ b/koucha/src/db/feed_channel.rs @@ -0,0 +1,131 @@ +use crate::{ + Result, + AdapterPool, + db::{ + Channel, + ChannelId, + Feed, + FeedId, + Item, + }, +}; + +pub struct UnparsedFeedChannel { + pub channel_id: i64, + pub feed_id: i64, +} +impl UnparsedFeedChannel { + pub fn parse(self) -> Result { + Ok(FeedChannel { + channel_id: ChannelId(self.channel_id), + feed_id: FeedId(self.feed_id) + }) + } +} + +pub struct FeedChannel { + channel_id: ChannelId, + feed_id: FeedId, +} + +impl FeedChannel { + pub async fn get_channel(&self, pool: &AdapterPool) -> Result { + Channel::get(pool, self.channel_id).await + } + pub async fn get_feed(&self, pool: &AdapterPool) -> Result { + Feed::get(pool, self.feed_id).await + } + + pub async fn add_item( + &self, pool: &AdapterPool, item: &Item + ) -> Result<()> { + let int_item_id = i64::from(item.id()); + let int_feed_id = i64::from(self.feed_id); + + sqlx::query!( + "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score) + VALUES (?, ?, 5)", // TODO: Add in scoring featuress + int_feed_id, int_item_id + ).execute(&pool.0).await?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use reqwest::Url; + use crate::{ + Adapter, + AdapterBuilder, + db::{ + Channel, + FeedId, + User + } + }; + + const FEED1: &str = "https://example.com/feed"; + + async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() + } + + // FeedChannel Tests + #[tokio::test] + async fn get_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let url = Url::parse(FEED1).unwrap(); + let channel = Channel::get_or_create(pool, url).await.unwrap(); + + let fc = FeedChannel { + channel_id: channel.id(), + feed_id: FeedId(1), // Fake Feed + }; + + let channel_from_fc = fc.get_channel(pool).await.unwrap(); + assert_eq!(channel_from_fc.id(), channel.id()); + } + + #[tokio::test] + async fn get_feed() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.id(), "My Feed").await.unwrap(); + + let fc = FeedChannel { + channel_id: ChannelId(1), // Fake Channel + feed_id: feed.id(), + }; + + let feed_from_fc = fc.get_feed(pool).await.unwrap(); + assert_eq!(feed_from_fc.id(), feed.id()); + } + + #[tokio::test] + pub async fn add_item() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.id(), "My Feed").await.unwrap(); + let url = Url::parse(FEED1).unwrap(); + let channel = Channel::get_or_create(pool, url).await.unwrap(); + let fc = FeedChannel { + channel_id: channel.id(), + feed_id: feed.id(), + }; + + let item = Item::get_or_create(pool, channel.id(), "item-guid").await.unwrap(); + fc.add_item(pool, &item).await.unwrap(); + + let items = feed.get_items(pool, 1, 0).await.unwrap(); + assert_eq!(items[0].id(), item.id()); + } +} diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs index 1cc7f6c..39a1b49 100644 --- a/koucha/src/db/item.rs +++ b/koucha/src/db/item.rs @@ -24,10 +24,11 @@ impl UnparsedItem { Ok(Item { id: ItemId(self.id), channel_id: ChannelId(self.channel_id), - fetched_at: self.fetched_at.as_deref() - .map(DateTime::parse_from_rfc2822) - .transpose()? - .map(|dt| dt.with_timezone(&Utc)), + fetched_at: match self.fetched_at { + Some(dt_str) => Some(DateTime::parse_from_rfc2822(&dt_str)? + .with_timezone(&Utc)), + None => None, + }, title: self.title, description: self.description, @@ -40,6 +41,7 @@ pub struct Item { id: ItemId, channel_id: ChannelId, + #[allow(dead_code)] // TODO: Use for score decay calculations later fetched_at: Option>, title: Option, description: Option, @@ -61,8 +63,8 @@ impl Item { let item = sqlx::query_as!( UnparsedItem, "INSERT INTO items (channel_id, guid) - VALUES(?, ?) - ON CONFLICT(id) DO UPDATE SET id = id + VALUES (?, ?) + ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id RETURNING id as `id!`, channel_id, fetched_at, title, description, content", int_channel_id, guid @@ -91,3 +93,43 @@ impl Item { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + use reqwest::Url; + use crate::{ + Adapter, + AdapterBuilder, + db::{ + Channel, + } + }; + + const FEED1: &str = "https://example.com/feed"; + const ITEM_GUID: &str = "item-guid"; + + async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() + } + + async fn setup_channel(pool: &AdapterPool) -> Channel { + let url = Url::parse(FEED1).unwrap(); + Channel::get_or_create(pool, url).await.unwrap() + } + + // Item Tests + #[tokio::test] + pub async fn get_or_create_duplicate() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let item1 = Item::get_or_create(pool, channel.id(), ITEM_GUID).await.unwrap(); + let item2 = Item::get_or_create(pool, channel.id(), ITEM_GUID).await.unwrap(); + + assert_eq!(item1.id(), item2.id()); + } +} From 544e380835760be9b9e91d26a9b09ffdcb59e0bd Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Mon, 26 Jan 2026 15:00:52 -0800 Subject: [PATCH 16/32] (Almost) full test coverage --- koucha/src/db/channel.rs | 120 +++++++++++++++++++++++++++++++--- koucha/src/db/feed.rs | 89 ++++++++++++++++++++----- koucha/src/db/feed_channel.rs | 24 ++++--- koucha/src/db/item.rs | 46 ++++++++----- koucha/src/db/user.rs | 118 ++++++++++++++++++++------------- koucha/src/fetch.rs | 74 ++++++++++++++++++++- koucha/src/lib.rs | 3 + koucha/src/test_utils.rs | 43 ++++++++++++ 8 files changed, 417 insertions(+), 100 deletions(-) create mode 100644 koucha/src/test_utils.rs diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 22bea40..0ea271b 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -160,19 +160,71 @@ impl Channel { #[cfg(test)] mod tests { use super::*; - use crate::{Adapter, AdapterBuilder}; + use crate::{ + db::{ + Feed, + User, + }, + test_utils::{ + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, USERNAME, FEED_TITLE, + FEED_TITLE2, ITEM_GUID, ITEM_GUID2, + setup_adapter, + setup_channel, + }, + }; + use chrono::TimeZone; + + #[test] + fn parse_unparsed_item() { + const CHANNEL_ID: i64 = 1; + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); - const FEED1: &str = "https://example.com/feed"; - const FEED2: &str = "https://example2.com/feed"; - - async fn setup_adapter() -> Adapter { - AdapterBuilder::new() - .database_url("sqlite::memory:") - .create().await.unwrap() + let raw_channel = UnparsedChannel { + id: CHANNEL_ID, + title: CHANNEL_TITLE.to_string(), + link: FEED1.to_string(), + description: Some(CHANNEL_DESC.to_string()), + last_fetched: Some(date.to_rfc2822()), + }; + let channel = raw_channel.parse().unwrap(); + + assert_eq!(channel.id.0, CHANNEL_ID); + assert_eq!(channel.title, CHANNEL_TITLE); + assert_eq!(channel.link.as_str(), FEED1); + assert_eq!(channel.description, Some(CHANNEL_DESC.to_string())); + assert_eq!(channel.last_fetched, Some(date)); } #[tokio::test] - async fn create_channel() { + async fn get_all() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url1 = Url::parse(FEED1).unwrap(); + let url2 = Url::parse(FEED2).unwrap(); + Channel::get_or_create(pool, url1).await.unwrap(); + Channel::get_or_create(pool, url2).await.unwrap(); + + let channels = Channel::get_all(pool).await.unwrap(); + assert_eq!(channels.len(), 2); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel_a = setup_channel(pool).await; + + let channel_b = Channel::get(pool, channel_a.id()).await.unwrap(); + + assert_eq!(channel_a.id, channel_b.id); + assert_eq!(channel_a.title, channel_b.title); + assert_eq!(channel_a.link, channel_b.link); + assert_eq!(channel_a.last_fetched, channel_b.last_fetched); + assert_eq!(channel_a.description, channel_b.description); + } + + #[tokio::test] + async fn create() { let adapter = setup_adapter().await; let pool = adapter.get_pool(); let url_feed = Url::parse(FEED1).unwrap(); @@ -213,4 +265,54 @@ mod tests { assert_eq!(channels.len(), 2); } + + #[tokio::test] + async fn get_feed_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let user = User::create(pool, USERNAME).await.unwrap(); + let feed1 = Feed::create(pool, user.id(), FEED_TITLE).await.unwrap(); + let feed2 = Feed::create(pool, user.id(), FEED_TITLE2).await.unwrap(); + + feed1.add_channel(pool, channel.id).await.unwrap(); + feed2.add_channel(pool, channel.id).await.unwrap(); + + let fc_list = channel.get_feed_channels(pool).await.unwrap(); + + assert_eq!(fc_list.len(), 2); + } + + #[tokio::test] + async fn get_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let user = User::create(pool, USERNAME).await.unwrap(); + let feed1 = Feed::create(pool, user.id(), FEED_TITLE).await.unwrap(); + let feed2 = Feed::create(pool, user.id(), FEED_TITLE2).await.unwrap(); + + feed1.add_channel(pool, channel.id).await.unwrap(); + feed2.add_channel(pool, channel.id).await.unwrap(); + + let fc_list = channel.get_feed_channels(pool).await.unwrap(); + + assert_eq!(fc_list.len(), 2); + } + + #[tokio::test] + async fn get_items() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + Item::get_or_create(pool, channel.id(), ITEM_GUID).await.unwrap(); + Item::get_or_create(pool, channel.id(), ITEM_GUID2).await.unwrap(); + + let items = channel.get_items(pool).await.unwrap(); + + assert_eq!(items.len(), 2); + } } diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index bb4783d..a769b1b 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -124,39 +124,96 @@ impl Feed { mod tests { use super::*; use crate::{ - Adapter, - AdapterBuilder, db::User, + test_utils::{ + FEED_TITLE, USERNAME, FEED1, FEED2, + setup_adapter, + setup_feed, + setup_channel, + } }; + use reqwest::Url; - async fn setup_adapter() -> Adapter { - AdapterBuilder::new() - .database_url("sqlite::memory:") - .create().await.unwrap() + #[test] + fn parse() { + const FID: i64 = 1; + let uf = UnparsedFeed { + id: FID, + title: FEED_TITLE.to_string(), + }; + + let f = uf.parse().unwrap(); + + assert_eq!(f.id.0, FID); + assert_eq!(f.title, FEED_TITLE); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + + let gotten_feed = Feed::get(pool, feed.id).await.unwrap(); + + assert_eq!(feed.id, gotten_feed.id); + assert_eq!(feed.title, gotten_feed.title); } #[tokio::test] - async fn create_feed() { + async fn create() { let adapter = setup_adapter().await; let pool = adapter.get_pool(); - let user = User::create(pool, "Alice").await.unwrap(); + let user = User::create(pool, USERNAME).await.unwrap(); + let feed = Feed::create(pool, user.id(), FEED_TITLE).await.unwrap(); - let feed = Feed::create(pool, user.id(), "Tech News").await.unwrap(); - - assert_eq!(feed.title(), "Tech News"); assert!(feed.id().0 > 0); + assert_eq!(feed.title(), FEED_TITLE); } #[tokio::test] - async fn test_update_title() { + async fn update_title() { + const NEW_FEED_TITLE: &str = "My NEW feed!"; let adapter = setup_adapter().await; let pool = adapter.get_pool(); - let user = User::create(pool, "Alice").await.unwrap(); - let feed = Feed::create(pool, user.id(), "Tech News").await.unwrap(); + let feed = setup_feed(pool).await; - Feed::update_title(pool, feed.id(), "Technology").await.unwrap(); + Feed::update_title(pool, feed.id(), NEW_FEED_TITLE).await.unwrap(); let updated = Feed::get(pool, feed.id()).await.unwrap(); - assert_eq!(updated.title(), "Technology"); + assert_eq!(updated.title(), NEW_FEED_TITLE); + } + + #[tokio::test] + async fn add_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + let channel = setup_channel(pool).await; + + feed.add_channel(pool, channel.id()).await.unwrap(); + + let channels = feed.get_channels(pool).await.unwrap(); + let gotten_channel = &channels[0]; + + assert_eq!(gotten_channel.id().0, channel.id().0); + } + + #[tokio::test] + async fn get_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + let url1 = Url::parse(FEED1).unwrap(); + let channel1 = Channel::get_or_create(pool, url1).await.unwrap(); + let url2 = Url::parse(FEED2).unwrap(); + let channel2 = Channel::get_or_create(pool, url2).await.unwrap(); + + feed.add_channel(pool, channel1.id()).await.unwrap(); + feed.add_channel(pool, channel2.id()).await.unwrap(); + + let channels = feed.get_channels(pool).await.unwrap(); + + assert_eq!(channels.len(), 2); } } diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs index 4421b88..19656cb 100644 --- a/koucha/src/db/feed_channel.rs +++ b/koucha/src/db/feed_channel.rs @@ -56,21 +56,29 @@ mod tests { use super::*; use reqwest::Url; use crate::{ - Adapter, - AdapterBuilder, db::{ Channel, FeedId, User - } + }, + test_utils::{ + FEED1, setup_adapter, + }, }; - const FEED1: &str = "https://example.com/feed"; + #[test] + fn parse() { + const CID: i64 = 1; + const FID: i64 = 1; + let ufc = UnparsedFeedChannel { + channel_id: CID, + feed_id: FID, + }; - async fn setup_adapter() -> Adapter { - AdapterBuilder::new() - .database_url("sqlite::memory:") - .create().await.unwrap() + let fc = ufc.parse().unwrap(); + + assert_eq!(fc.channel_id.0, CID); + assert_eq!(fc.feed_id.0, FID); } // FeedChannel Tests diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs index 39a1b49..cb25331 100644 --- a/koucha/src/db/item.rs +++ b/koucha/src/db/item.rs @@ -97,32 +97,42 @@ impl Item { #[cfg(test)] mod tests { use super::*; - use reqwest::Url; - use crate::{ - Adapter, - AdapterBuilder, - db::{ - Channel, - } + use crate::test_utils::{ + ITEM_GUID, ITEM_TITLE, ITEM_DESC, ITEM_CONT, + setup_adapter, + setup_channel, }; + use chrono::TimeZone; - const FEED1: &str = "https://example.com/feed"; - const ITEM_GUID: &str = "item-guid"; + // UnparsedItem tests + #[test] + fn parse_unparsed_item() { + const ITEM_ID: i64 = 1; + const CHANNEL_ID: i64 = 1; - async fn setup_adapter() -> Adapter { - AdapterBuilder::new() - .database_url("sqlite::memory:") - .create().await.unwrap() - } + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + let raw_item = UnparsedItem { + id: ITEM_ID, + channel_id: CHANNEL_ID, + fetched_at: Some(date.to_rfc2822()), + title: Some(ITEM_TITLE.to_string()), + description: Some(ITEM_DESC.to_string()), + content: Some(ITEM_CONT.to_string()), + }; + let item = raw_item.parse().unwrap(); + + assert_eq!(item.id.0, ITEM_ID); + assert_eq!(item.channel_id.0, CHANNEL_ID); + assert_eq!(item.fetched_at, Some(date)); + assert_eq!(item.title, Some(ITEM_TITLE.to_string())); + assert_eq!(item.description, Some(ITEM_DESC.to_string())); + assert_eq!(item.content, Some(ITEM_CONT.to_string())); - async fn setup_channel(pool: &AdapterPool) -> Channel { - let url = Url::parse(FEED1).unwrap(); - Channel::get_or_create(pool, url).await.unwrap() } // Item Tests #[tokio::test] - pub async fn get_or_create_duplicate() { + async fn get_or_create_duplicate() { let adapter = setup_adapter().await; let pool = adapter.get_pool(); let channel = setup_channel(pool).await; diff --git a/koucha/src/db/user.rs b/koucha/src/db/user.rs index 05b7a4b..63f24d8 100644 --- a/koucha/src/db/user.rs +++ b/koucha/src/db/user.rs @@ -39,6 +39,7 @@ impl User { user } + pub async fn get_all(pool: &AdapterPool) -> Result> { let users: Result> = sqlx::query_as!( UnparsedUser, @@ -88,93 +89,118 @@ impl User { #[cfg(test)] mod tests { use super::*; - use crate::{AdapterBuilder, Adapter}; + use crate::{ + db::Feed, + test_utils::{ + USERNAME, USERNAME2, FEED_TITLE, FEED_TITLE2, + setup_adapter, + }, + }; - async fn setup_adapter() -> Adapter { - AdapterBuilder::new() - .database_url("sqlite::memory:") - .create().await.unwrap() + #[test] + fn parse() { + const UID: i64 = 1; + let unparsed_user = UnparsedUser { + id: UID, + name: USERNAME.to_string(), + }; + + let user = unparsed_user.parse().unwrap(); + assert_eq!(user.id.0, UID); + assert_eq!(user.name, USERNAME); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let new_user = User::create(pool, USERNAME).await.unwrap(); + + let fetched_user = User::get(pool, new_user.id).await.unwrap(); + assert_eq!(fetched_user.name, USERNAME); + assert_eq!(fetched_user.id.0, 1); } #[tokio::test] - async fn get_user() { + async fn get_all() { let adapter = setup_adapter().await; let pool = adapter.get_pool(); + User::create(pool, USERNAME).await.unwrap(); + User::create(pool, USERNAME2).await.unwrap(); - let new_user = User::create(pool, "Alice").await.unwrap(); - - let fetched_user = User::get(pool, new_user.id).await.unwrap(); - assert_eq!(fetched_user.name, "Alice"); - assert!(fetched_user.id.0 > 0); + let users = User::get_all(pool).await.unwrap(); + assert_eq!(users.len(), 2); + assert!(users.iter().any(|u| u.name == USERNAME)); + assert!(users.iter().any(|u| u.name == USERNAME2)); } #[tokio::test] async fn create_user() { let adapter = setup_adapter().await; - let pool = adapter.get_pool(); + let pool = adapter.get_pool(); - let user = User::create(pool, "Alice").await.unwrap(); + let user = User::create(pool, USERNAME).await.unwrap(); - assert_eq!(user.name, "Alice"); - assert!(user.id.0 > 0); + assert_eq!(user.name, USERNAME); + assert_eq!(user.id.0, 1); } - + #[tokio::test] async fn create_duplicate_user() { let adapter = setup_adapter().await; - let pool = adapter.get_pool(); + let pool = adapter.get_pool(); - let _user = User::create(pool, "Alice").await.unwrap(); - let duplicate_user = User::create(pool, "Alice").await; + User::create(pool, USERNAME).await.unwrap(); + let duplicate_user = User::create(pool, USERNAME).await; assert!(duplicate_user.is_err()); } - - #[tokio::test] - async fn get_all_users() { - let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - - User::create(pool, "Alice").await.unwrap(); - User::create(pool, "Bob").await.unwrap(); - - let users = User::get_all(pool).await.unwrap(); - - assert_eq!(users.len(), 2); - assert!(users.iter().any(|u| u.name == "Alice")); - assert!(users.iter().any(|u| u.name == "Bob")); - } #[tokio::test] async fn update_name() { + const NEW_USERNAME: &str = "Alicia"; + assert!(NEW_USERNAME != USERNAME); let adapter = setup_adapter().await; - let pool = adapter.get_pool(); + let pool = adapter.get_pool(); - let user = User::create(pool, "Alice").await.unwrap(); - User::update_name(pool, user.id, "Alicia").await.unwrap(); + let user = User::create(pool, USERNAME).await.unwrap(); + User::update_name(pool, user.id, NEW_USERNAME).await.unwrap(); let updated = User::get(pool, user.id).await.unwrap(); - assert_eq!(updated.name, "Alicia"); + assert_eq!(updated.name, NEW_USERNAME); } - + #[tokio::test] async fn update_name_to_duplicate() { let adapter = setup_adapter().await; - let pool = adapter.get_pool(); + let pool = adapter.get_pool(); - let alice = User::create(pool, "Alice").await.unwrap(); - let _sam = User::create(pool, "Sam").await.unwrap(); - let status = User::update_name(pool, alice.id, "Sam").await; + let user1 = User::create(pool, USERNAME).await.unwrap(); + User::create(pool, USERNAME2).await.unwrap(); + let status = User::update_name(pool, user1.id, USERNAME2).await; assert!(status.is_err()); } + #[tokio::test] + async fn get_feeds() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + Feed::create(pool, user.id, FEED_TITLE).await.unwrap(); + Feed::create(pool, user.id, FEED_TITLE2).await.unwrap(); + + let feeds = user.get_feeds(pool).await.unwrap(); + assert_eq!(feeds.len(), 2); + assert!(feeds.iter().any(|f| f.title() == FEED_TITLE)); + assert!(feeds.iter().any(|f| f.title() == FEED_TITLE2)); + } + #[tokio::test] async fn get_feeds_empty() { let adapter = setup_adapter().await; - let pool = adapter.get_pool(); - - let user = User::create(pool, "Alice").await.unwrap(); + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); let feeds = user.get_feeds(pool).await.unwrap(); assert_eq!(feeds.len(), 0); diff --git a/koucha/src/fetch.rs b/koucha/src/fetch.rs index b71b30c..62e4505 100644 --- a/koucha/src/fetch.rs +++ b/koucha/src/fetch.rs @@ -70,10 +70,12 @@ impl FetchedRSSChannel { let rss_channel = rss::Channel::read_from(&bytestream[..])?; - Ok(Some(FetchedRSSChannel::parse(rss_channel)?)) + let now = Utc::now(); + + Ok(Some(FetchedRSSChannel::parse(rss_channel, now)?)) } - fn parse(rss: rss::Channel) -> Result { + fn parse(rss: rss::Channel, fetched_at: DateTime) -> Result { Ok(FetchedRSSChannel { title: rss.title, link: Url::parse(&rss.link)?, @@ -81,7 +83,73 @@ impl FetchedRSSChannel { items: rss.items.into_iter().map(FetchedRSSItem::parse).collect(), - fetched_at: Utc::now(), + fetched_at: fetched_at, }) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::{ + ITEM_TITLE, ITEM_GUID, ITEM_GUID2, ITEM_DESC, ITEM_CONT, + CHANNEL_TITLE, CHANNEL_DESC, FEED1 + }; + use chrono::TimeZone; + + fn create_guid(value: String) -> rss::Guid { + rss::Guid { value, permalink: false } + } + + fn create_item(guid: rss::Guid) -> rss::Item { + rss::ItemBuilder::default() + .title(ITEM_TITLE.to_string()) + .guid(guid) + .description(ITEM_DESC.to_string()) + .content(ITEM_CONT.to_string()) + .build() + } + + fn create_channel(items: Vec) -> rss::Channel { + rss::ChannelBuilder::default() + .title(CHANNEL_TITLE.to_string()) + .description(CHANNEL_DESC.to_string()) + .link(FEED1.to_string()) + .items(items) + .build() + } + + #[test] + fn parse_item() { + let rss_guid = create_guid(ITEM_GUID.to_string()); + let rss_item = create_item(rss_guid); + let item = FetchedRSSItem::parse(rss_item); + + assert_eq!(item.guid, ITEM_GUID); + assert_eq!(item.title, ITEM_TITLE); + assert_eq!(item.description, ITEM_DESC); + assert_eq!(item.content, ITEM_CONT); + } + + #[test] + fn parse_feed() { + let rss_guid = create_guid(ITEM_GUID.to_string()); + let rss_guid2 = create_guid(ITEM_GUID2.to_string()); + let rss_item = create_item(rss_guid); + let rss_item2 = create_item(rss_guid2); + + let rss_channel = create_channel([rss_item, rss_item2].to_vec()); + + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + + let channel = FetchedRSSChannel::parse(rss_channel, date).unwrap(); + + assert_eq!(channel.title, CHANNEL_TITLE); + assert_eq!(channel.link.as_str(), FEED1); + assert_eq!(channel.description, CHANNEL_DESC); + assert_eq!(channel.fetched_at, date); + assert_eq!(channel.items.len(), 2); + assert!(channel.items.iter().any(|i| i.guid() == ITEM_GUID)); + assert!(channel.items.iter().any(|i| i.guid() == ITEM_GUID2)); + } +} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 1e29303..a9de79f 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -5,6 +5,9 @@ type Result = std::result::Result>; pub mod db; pub mod fetch; +#[cfg(test)] +pub mod test_utils; + pub struct AdapterPool(sqlx::SqlitePool); pub struct AdapterClient(reqwest::Client); diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs new file mode 100644 index 0000000..5f2cb9b --- /dev/null +++ b/koucha/src/test_utils.rs @@ -0,0 +1,43 @@ +#![cfg(test)] + +use crate::{ + Adapter, + AdapterBuilder, + AdapterPool, + db::{ + Channel, + Feed, + User, + } +}; +use reqwest::Url; + +pub const FEED1: &str = "https://example.com/feed"; +pub const FEED2: &str = "https://example2.com/feed"; +pub const USERNAME: &str = "Alice"; +pub const USERNAME2: &str = "Bob"; +pub const FEED_TITLE: &str = "My Feed!"; +pub const FEED_TITLE2: &str = "My Second Feed!"; +pub const CHANNEL_TITLE: &str = "My Channel!"; +pub const CHANNEL_DESC: &str = "My Channel's description"; +pub const ITEM_GUID: &str = "item-guid"; +pub const ITEM_GUID2: &str = "item-guid2"; +pub const ITEM_TITLE: &str = "My Item!"; +pub const ITEM_DESC: &str = "My Item's description"; +pub const ITEM_CONT: &str = "The content of my Item"; + +pub async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() +} + +pub async fn setup_channel(pool: &AdapterPool) -> Channel { + let url = Url::parse(FEED1).unwrap(); + Channel::get_or_create(pool, url).await.unwrap() +} + +pub async fn setup_feed(pool: &AdapterPool) -> Feed { + let user = User::create(pool, USERNAME).await.unwrap(); + Feed::create(pool, user.id(), FEED_TITLE).await.unwrap() +} From 5487a1801fdb4f645699247c4f9146f455cf4efa Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Sun, 1 Feb 2026 13:04:33 -0800 Subject: [PATCH 17/32] scoring starter code, and flake to stable --- flake.lock | 8 +- flake.nix | 2 +- .../20260115003047_initial_schema.sql | 4 +- koucha/src/db.rs | 1 - koucha/src/lib.rs | 1 + koucha/src/score.rs | 89 +++++++++++++++++++ 6 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 koucha/src/score.rs diff --git a/flake.lock b/flake.lock index 2972d8a..c4fa525 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1768127708, - "narHash": "sha256-1Sm77VfZh3mU0F5OqKABNLWxOuDeHIlcFjsXeeiPazs=", + "lastModified": 1769933782, + "narHash": "sha256-GlZemJ2dxhXMMq6TNyt588OFv4/jIt3J1QVBO9MspBE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ffbc9f8cbaacfb331b6017d5a5abb21a492c9a38", + "rev": "64728753f1a42c81c5688a136a6bee173665acc9", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixos-25.11-small", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 79e3a0f..f48d72e 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Koucha rust flake"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11-small"; }; outputs = { self, nixpkgs }: diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql index 63d3591..ae2418e 100644 --- a/koucha/migrations/20260115003047_initial_schema.sql +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -39,7 +39,9 @@ CREATE TABLE feeds ( CREATE TABLE feed_channels ( feed_id INTEGER NOT NULL, channel_id INTEGER NOT NULL, - -- Decay settings will go here + initial_score INTEGER, + gravity INTEGER, + boost INTEGER, PRIMARY KEY (feed_id, channel_id), FOREIGN KEY (feed_id) REFERENCES feeds(id), FOREIGN KEY (channel_id) REFERENCES channels(id) diff --git a/koucha/src/db.rs b/koucha/src/db.rs index 79eaf50..2456bd9 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -9,7 +9,6 @@ pub use channel::Channel; mod item; pub use item::Item; - macro_rules! define_id { ($name:ident) => { #[derive(PartialEq, Debug, Copy, Clone)] diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index a9de79f..a20a9dc 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -4,6 +4,7 @@ type Result = std::result::Result>; pub mod db; pub mod fetch; +pub mod score; #[cfg(test)] pub mod test_utils; diff --git a/koucha/src/score.rs b/koucha/src/score.rs new file mode 100644 index 0000000..7c54b63 --- /dev/null +++ b/koucha/src/score.rs @@ -0,0 +1,89 @@ +use chrono::{DateTime, Utc, TimeDelta}; + +mod default { + pub const INITIAL_SCORE: i64 = 70; + pub const GRAVITY: i64 = -10; + pub const BOOST: i64 = 12; +} + +macro_rules! rich_i64 { + ($name:ident, $default:expr) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } + impl $name { + pub fn new(value: Option) -> Self { + Self(value.unwrap_or($default)) + } + } + }; +} + +rich_i64!(Gravity, default::GRAVITY); +rich_i64!(Boost, default::BOOST); +impl Boost { + fn should_apply( + old_boost_time: Option>, new_boost_time: DateTime + ) -> bool { + old_boost_time.map_or(true, |obs| { + let time_delta = obs - &new_boost_time; + time_delta.num_days() >= 1 + }) + } +} +pub struct Score { + value: i64, + last_updated: DateTime, + last_boosted: Option>, +} + +impl Score { + pub fn new() -> Self { + Self::new_at_time(Utc::now()) + } + + pub fn new_at_time(creation_time: DateTime) -> Self { + Score { + value: default::INITIAL_SCORE, + last_updated: creation_time, + last_boosted: Some(creation_time), + } + } + + pub fn update(self) -> Self { + self.update_at_time(Utc::now()) + } + + pub fn update_at_time(self, update_time: DateTime) -> Self { + let to_elapse_from = self.last_boosted.map_or(self.last_updated, |lb| { + std::cmp::max(self.last_updated, lb + TimeDelta::days(1)) + }); + let elapsed_time = update_time.signed_duration_since(to_elapse_from); + + self + } + + pub fn boost(self, boost: Boost) -> Self { + self.boost_at_time(boost, Utc::now()) + } + + // This function does not "fast-forward" the score's value to the time of + // boost, but still updates `last_updated`. Meaning that hours of gravity may + // not be applied. + // The expectation is that a boost is a user interaction, and that the user + // should be seeing a "fresh" score. We wouldn't want a boost to end up + // applying lots of gravity. But care should be taken to ensure that only + // "fresh" scores are boosted. Or that boost_time reflects the state of the + // user experience. + pub fn boost_at_time(self, boost: Boost, boost_time: DateTime) -> Self { + if Boost::should_apply(self.last_boosted, boost_time) { + Self { + value: self.value + i64::from(boost), + last_updated: boost_time, + last_boosted: Some(boost_time), + } + } else { + self + } + } +} From e353977da9d3f6476550459e9a0c85ed1d32b074 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Mon, 2 Feb 2026 14:50:50 -0800 Subject: [PATCH 18/32] finalized score (for now lol) --- koucha/src/score.rs | 182 +++++++++++++++++++++++++++++++------------- 1 file changed, 131 insertions(+), 51 deletions(-) diff --git a/koucha/src/score.rs b/koucha/src/score.rs index 7c54b63..d8ff046 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -1,10 +1,15 @@ use chrono::{DateTime, Utc, TimeDelta}; +use crate::{Result}; mod default { + use crate::score::SECONDS_IN_A_DAY; + pub const INITIAL_SCORE: i64 = 70; pub const GRAVITY: i64 = -10; pub const BOOST: i64 = 12; + pub const BOOST_FREEZE_IN_SECONDS: i64 = SECONDS_IN_A_DAY; } +const SECONDS_IN_A_DAY: i64 = 60 * 60 * 24; macro_rules! rich_i64 { ($name:ident, $default:expr) => { @@ -21,69 +26,144 @@ macro_rules! rich_i64 { rich_i64!(Gravity, default::GRAVITY); rich_i64!(Boost, default::BOOST); -impl Boost { - fn should_apply( - old_boost_time: Option>, new_boost_time: DateTime - ) -> bool { - old_boost_time.map_or(true, |obs| { - let time_delta = obs - &new_boost_time; - time_delta.num_days() >= 1 - }) +pub struct UnparsedScore { + pub value: i64, + pub last_updated: DateTime, + pub last_boosted: Option>, +} + +impl UnparsedScore { + pub fn parse(self) -> Score { + match self.last_boosted { + None => Score::Decaying(DecayingScore { + value: self.value, + last_updated: self.last_updated, + }), + Some(last_boosted) => Score::Boosted(BoostedScore { + value: self.value, + boosted_at: last_boosted, + }), + } } } -pub struct Score { - value: i64, - last_updated: DateTime, - last_boosted: Option>, + +pub enum Score { + Decaying(DecayingScore), + Boosted(BoostedScore), } impl Score { - pub fn new() -> Self { - Self::new_at_time(Utc::now()) - } - - pub fn new_at_time(creation_time: DateTime) -> Self { - Score { + pub fn new() -> DecayingScore { + DecayingScore { value: default::INITIAL_SCORE, - last_updated: creation_time, - last_boosted: Some(creation_time), + last_updated: Utc::now(), } } - pub fn update(self) -> Self { - self.update_at_time(Utc::now()) + pub fn get_score(&self) -> i64 { + match self { + Self::Decaying(s) => s.get_score(), + Self::Boosted(b) => b.get_score(), + } } - pub fn update_at_time(self, update_time: DateTime) -> Self { - let to_elapse_from = self.last_boosted.map_or(self.last_updated, |lb| { - std::cmp::max(self.last_updated, lb + TimeDelta::days(1)) - }); - let elapsed_time = update_time.signed_duration_since(to_elapse_from); - - self - } - - pub fn boost(self, boost: Boost) -> Self { - self.boost_at_time(boost, Utc::now()) - } - - // This function does not "fast-forward" the score's value to the time of - // boost, but still updates `last_updated`. Meaning that hours of gravity may - // not be applied. - // The expectation is that a boost is a user interaction, and that the user - // should be seeing a "fresh" score. We wouldn't want a boost to end up - // applying lots of gravity. But care should be taken to ensure that only - // "fresh" scores are boosted. Or that boost_time reflects the state of the - // user experience. - pub fn boost_at_time(self, boost: Boost, boost_time: DateTime) -> Self { - if Boost::should_apply(self.last_boosted, boost_time) { - Self { - value: self.value + i64::from(boost), - last_updated: boost_time, - last_boosted: Some(boost_time), + pub fn update_score(self, gravity: Gravity) -> Self { + match self { + Self::Decaying(d) => Score::Decaying(d.update_score(gravity)), + Self::Boosted(b) => { + let try_unfrozen = b.try_unfreeze(); + match try_unfrozen { + Self::Decaying(s) => Score::Decaying(s.update_score(gravity)), + Self::Boosted(b) => Score::Boosted(b), + } } - } else { - self + } + } + + pub fn get_decaying(self) -> Result { + match self { + Self::Decaying(s) => Ok(s), + Self::Boosted(_) => Err("Attempted to get_decaying() of a boosted score".into()), + } + } + + pub fn get_boosted(self) -> Result { + match self { + Self::Decaying(_) => Err("Attempted to get_boosted() of a decaying score".into()), + Self::Boosted(b) => Ok(b), + } + } +} + +pub struct BoostedScore { + value: i64, + boosted_at: DateTime, +} + +pub struct DecayingScore { + value: i64, + last_updated: DateTime, +} + +impl DecayingScore { + fn get_score(&self) -> i64 { + self.value + } + + fn update_score(self, gravity: Gravity) -> Self { + self.update_score_at_time(gravity, Utc::now()) + } + + fn update_score_at_time( + self, gravity: Gravity, update_time: DateTime + ) -> Self { + let elapsed_time: TimeDelta = update_time.signed_duration_since(self.last_updated); + let new_value = if elapsed_time <= TimeDelta::zero() { self.value } else { + i64::from(gravity) * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) + }; + Self { + last_updated: update_time, + value: new_value, + } + } + + pub fn boost(self, boost: Boost) -> BoostedScore { + self.boost_at_time(boost, Utc::now()) + } + + fn boost_at_time(self, boost: Boost, boost_time: DateTime) -> BoostedScore { + BoostedScore { + value: self.value + i64::from(boost), + boosted_at: boost_time, + } + } +} + +impl BoostedScore { + fn get_score(&self) -> i64 { + self.value + } + + pub fn unboost(self, boost: Boost) -> DecayingScore { + DecayingScore { + value: self.value - i64::from(boost), + last_updated: self.boosted_at, + } + } + + fn try_unfreeze(self) -> Score { + self.try_unfreeze_at_time(Utc::now()) + } + + fn try_unfreeze_at_time(self, update_time: DateTime) -> Score { + let boost_end = self.boosted_at + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + if boost_end > update_time { + Score::Decaying(DecayingScore { + value: self.value, + last_updated: boost_end, + }) + } else { + Score::Boosted(self) } } } From 91229287a8974a2df5fe0296f7b77e0e11c2e860 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 3 Feb 2026 16:15:50 -0800 Subject: [PATCH 19/32] Score tests, and get_datetime test-util --- koucha/src/fetch.rs | 6 +- koucha/src/score.rs | 249 ++++++++++++++++++++++++++++++++++++--- koucha/src/test_utils.rs | 10 ++ 3 files changed, 246 insertions(+), 19 deletions(-) diff --git a/koucha/src/fetch.rs b/koucha/src/fetch.rs index 62e4505..532b4fe 100644 --- a/koucha/src/fetch.rs +++ b/koucha/src/fetch.rs @@ -93,9 +93,9 @@ mod tests { use super::*; use crate::test_utils::{ ITEM_TITLE, ITEM_GUID, ITEM_GUID2, ITEM_DESC, ITEM_CONT, - CHANNEL_TITLE, CHANNEL_DESC, FEED1 + CHANNEL_TITLE, CHANNEL_DESC, FEED1, + get_datetime }; - use chrono::TimeZone; fn create_guid(value: String) -> rss::Guid { rss::Guid { value, permalink: false } @@ -140,7 +140,7 @@ mod tests { let rss_channel = create_channel([rss_item, rss_item2].to_vec()); - let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + let date: DateTime = get_datetime(); let channel = FetchedRSSChannel::parse(rss_channel, date).unwrap(); diff --git a/koucha/src/score.rs b/koucha/src/score.rs index d8ff046..4cdac60 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -54,9 +54,19 @@ pub enum Score { impl Score { pub fn new() -> DecayingScore { + Self::new_with_initial(default::INITIAL_SCORE) + } + + pub fn new_with_initial(initial_score: i64) -> DecayingScore { + Self::new_with_initial_and_time(initial_score, Utc::now()) + } + + pub fn new_with_initial_and_time( + initial: i64, time: DateTime + ) -> DecayingScore { DecayingScore { - value: default::INITIAL_SCORE, - last_updated: Utc::now(), + value: initial, + last_updated: time, } } @@ -68,12 +78,20 @@ impl Score { } pub fn update_score(self, gravity: Gravity) -> Self { + self.update_score_at_time(gravity, Utc::now()) + } + + fn update_score_at_time(self, gravity: Gravity, time: DateTime) -> Self { match self { - Self::Decaying(d) => Score::Decaying(d.update_score(gravity)), + Self::Decaying(d) => Score::Decaying( + d.apply_gravity_to_time(gravity, time) + ), Self::Boosted(b) => { - let try_unfrozen = b.try_unfreeze(); + let try_unfrozen = b.try_unfreeze_at_time(time); match try_unfrozen { - Self::Decaying(s) => Score::Decaying(s.update_score(gravity)), + Self::Decaying(s) => Score::Decaying( + s.apply_gravity_to_time(gravity, time) + ), Self::Boosted(b) => Score::Boosted(b), } } @@ -110,16 +128,12 @@ impl DecayingScore { self.value } - fn update_score(self, gravity: Gravity) -> Self { - self.update_score_at_time(gravity, Utc::now()) - } - - fn update_score_at_time( + fn apply_gravity_to_time( self, gravity: Gravity, update_time: DateTime ) -> Self { let elapsed_time: TimeDelta = update_time.signed_duration_since(self.last_updated); let new_value = if elapsed_time <= TimeDelta::zero() { self.value } else { - i64::from(gravity) * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) + self.value + i64::from(gravity) * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) }; Self { last_updated: update_time, @@ -151,13 +165,9 @@ impl BoostedScore { } } - fn try_unfreeze(self) -> Score { - self.try_unfreeze_at_time(Utc::now()) - } - fn try_unfreeze_at_time(self, update_time: DateTime) -> Score { let boost_end = self.boosted_at + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); - if boost_end > update_time { + if boost_end < update_time { Score::Decaying(DecayingScore { value: self.value, last_updated: boost_end, @@ -167,3 +177,210 @@ impl BoostedScore { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::get_datetime; + + #[test] + fn gravity_default() { + let gravity = Gravity::new(None); + assert_eq!(i64::from(gravity), default::GRAVITY); + } + + #[test] + fn boost_default() { + let boost = Boost::new(None); + assert_eq!(i64::from(boost), default::BOOST); + } + + // "Score" Tests + + #[test] + fn parse_decaying() { + let ups = UnparsedScore { + value: 10, + last_updated: get_datetime(), + last_boosted: None, + }; + + ups.parse().get_decaying().unwrap(); + } + + #[test] + fn parse_boosted() { + let dt = get_datetime(); + let ups = UnparsedScore { + value: 10, + last_updated: dt, + last_boosted: Some(dt), + }; + + ups.parse().get_boosted().unwrap(); + } + + #[test] + fn new() { + let score = Score::new(); + assert_eq!(score.value, default::INITIAL_SCORE); + } + + #[test] + fn new_with_values() { + let dt = get_datetime(); + let score = Score::new_with_initial_and_time(10, dt); + assert_eq!(score.value, 10); + assert_eq!(score.last_updated, dt); + } + + #[test] + fn update_score_stays_decaying() { + let dt = get_datetime(); + let score = Score::Decaying(Score::new_with_initial_and_time(10, dt)); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); + + score.update_score_at_time(gravity, dt2).get_decaying().unwrap(); + } + + #[test] + fn update_score_stays_frozen() { + let dt = get_datetime(); + let score = Score::Boosted(BoostedScore { value: 10, boosted_at: dt }); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + + score.update_score_at_time(gravity, dt2).get_boosted().unwrap(); + } + + #[test] + fn update_score_thaws_and_decays() { + let dt = get_datetime(); + let score = Score::Boosted(BoostedScore { value: 10, boosted_at: dt }); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds( + default::BOOST_FREEZE_IN_SECONDS + SECONDS_IN_A_DAY + ); + + let updated = score.update_score_at_time(gravity, dt2) + .get_decaying().unwrap(); + assert!(updated.value < 10) + } + + #[test] + fn get_decaying_success() { + let dt = get_datetime(); + let score = Score::Decaying(Score::new_with_initial_and_time(10, dt)); + + score.get_decaying().unwrap(); + } + + #[test] + #[should_panic = "Attempted to get_boosted() of a decaying score"] + fn get_boosted_failure() { + let dt = get_datetime(); + let score = Score::Decaying(Score::new_with_initial_and_time(10, dt)); + + score.get_boosted().unwrap(); + } + + #[test] + #[should_panic = "Attempted to get_decaying() of a boosted score"] + fn get_decaying_failure() { + let dt = get_datetime(); + let boost = Boost::new(None); + let score = Score::Boosted( + Score::new_with_initial_and_time(10, dt).boost_at_time(boost, dt) + ); + + score.get_decaying().unwrap(); + } + + #[test] + fn get_boosted_success() { + let dt = get_datetime(); + let boost = Boost::new(None); + let score = Score::Boosted( + Score::new_with_initial_and_time(10, dt).boost_at_time(boost, dt) + ); + + score.get_boosted().unwrap(); + } + + // "DecayingScore" Tests + + #[test] + fn apply_gravity_to_future() { + let dt = get_datetime(); + let score = DecayingScore { value: 10, last_updated: dt }; + let future = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); + let gravity = Gravity::new(None); + + let updated = score.apply_gravity_to_time(gravity, future); + + assert_eq!(updated.value, 10 + default::GRAVITY); + assert_eq!(updated.last_updated, future); + } + + #[test] + fn apply_gravity_to_past() { + let dt = get_datetime(); + let score = DecayingScore { value: 10, last_updated: dt }; + let past = dt - TimeDelta::seconds(SECONDS_IN_A_DAY); + let gravity = Gravity::new(None); + + let updated = score.apply_gravity_to_time(gravity, past); + + assert_eq!(updated.value, 10); + assert_eq!(updated.last_updated, past); + } + + #[test] + fn boost() { + let dt = get_datetime(); + let score = DecayingScore { value: 10, last_updated: dt }; + let boost = Boost::new(None); + + let boosted = score.boost_at_time(boost, dt); + assert_eq!(boosted.value, 10 + default::BOOST); + assert_eq!(boosted.boosted_at, dt); + } + + // "BoostedScore" tests + + #[test] + fn unboost() { + let dt = get_datetime(); + let score = DecayingScore { value: 10, last_updated: dt }; + let boost = Boost::new(None); + let boosted = score.boost_at_time(boost, dt); + + let unboosted = boosted.unboost(boost); + assert_eq!(unboosted.value, 10); + assert_eq!(unboosted.last_updated, dt); + } + + #[test] + fn boosted_stays_frozen() { + let dt = get_datetime(); + let score = BoostedScore { value: 10, boosted_at: dt }; + + let last_second = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + + score.try_unfreeze_at_time(last_second).get_boosted().unwrap(); + } + + #[test] + fn boosted_thaws() { + let dt = get_datetime(); + let score = BoostedScore { value: 10, boosted_at: dt }; + + let first_second = dt + TimeDelta::days(default::BOOST_FREEZE_IN_SECONDS+1); + + score.try_unfreeze_at_time(first_second).get_decaying().unwrap(); + } +} diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index 5f2cb9b..870a257 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -11,6 +11,11 @@ use crate::{ } }; use reqwest::Url; +use chrono::{ + Utc, + TimeZone, + DateTime +}; pub const FEED1: &str = "https://example.com/feed"; pub const FEED2: &str = "https://example2.com/feed"; @@ -26,6 +31,11 @@ pub const ITEM_TITLE: &str = "My Item!"; pub const ITEM_DESC: &str = "My Item's description"; pub const ITEM_CONT: &str = "The content of my Item"; + +pub fn get_datetime() -> DateTime { + Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() +} + pub async fn setup_adapter() -> Adapter { AdapterBuilder::new() .database_url("sqlite::memory:") From 25f00d1665e7e5bde39fecd18fbbd0f919ff106b Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 3 Feb 2026 17:51:09 -0800 Subject: [PATCH 20/32] Score refactor, add scores to feed_channels --- .../20260115003047_initial_schema.sql | 2 + koucha/src/db/channel.rs | 2 +- koucha/src/db/feed_channel.rs | 59 +++++- koucha/src/score.rs | 181 +++++++++++------- 4 files changed, 166 insertions(+), 78 deletions(-) diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql index ae2418e..b863eee 100644 --- a/koucha/migrations/20260115003047_initial_schema.sql +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -51,6 +51,8 @@ CREATE TABLE feed_items ( item_id INTEGER NOT NULL, feed_id INTEGER NOT NULL, score INTEGER NOT NULL, + last_updated TEXT NOT NULL, + boosted_at TEXT, archived BOOLEAN DEFAULT FALSE, PRIMARY KEY (item_id, feed_id), FOREIGN KEY (feed_id) REFERENCES feeds(id), diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 0ea271b..6df59fb 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -115,7 +115,7 @@ impl Channel { ) -> Result> { let feeds: Result> = sqlx::query_as!( UnparsedFeedChannel, - "SELECT channel_id, feed_id + "SELECT channel_id, feed_id, initial_score, gravity, boost FROM feed_channels WHERE channel_id = ?", self.id.0 diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs index 19656cb..0640555 100644 --- a/koucha/src/db/feed_channel.rs +++ b/koucha/src/db/feed_channel.rs @@ -8,17 +8,29 @@ use crate::{ FeedId, Item, }, + score::{ + Score, + Gravity, + Boost, + }, }; +use chrono::{Utc, DateTime}; pub struct UnparsedFeedChannel { pub channel_id: i64, pub feed_id: i64, + pub initial_score: Option, + pub gravity: Option, + pub boost: Option, } impl UnparsedFeedChannel { pub fn parse(self) -> Result { Ok(FeedChannel { channel_id: ChannelId(self.channel_id), - feed_id: FeedId(self.feed_id) + feed_id: FeedId(self.feed_id), + initial_score: Score::new(self.initial_score), + gravity: Gravity::new(self.gravity), + boost: Boost::new(self.boost), }) } } @@ -26,6 +38,9 @@ impl UnparsedFeedChannel { pub struct FeedChannel { channel_id: ChannelId, feed_id: FeedId, + initial_score: Score, + gravity: Gravity, + boost: Boost, } impl FeedChannel { @@ -38,17 +53,26 @@ impl FeedChannel { pub async fn add_item( &self, pool: &AdapterPool, item: &Item + ) -> Result<()> { + self.add_item_at(pool, item, Utc::now()).await + } + + async fn add_item_at( + &self, pool: &AdapterPool, item: &Item, add_at: DateTime ) -> Result<()> { let int_item_id = i64::from(item.id()); let int_feed_id = i64::from(self.feed_id); + let int_initial_score = i64::from(self.initial_score); + let string_last_updated = add_at.to_rfc2822(); sqlx::query!( - "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score) - VALUES (?, ?, 5)", // TODO: Add in scoring featuress - int_feed_id, int_item_id + "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated) + VALUES (?, ?, ?, ?)", + int_feed_id, int_item_id, int_initial_score, string_last_updated ).execute(&pool.0).await?; Ok(()) } + } #[cfg(test)] @@ -62,23 +86,32 @@ mod tests { User }, test_utils::{ - FEED1, setup_adapter, + FEED1, setup_adapter, get_datetime }, }; #[test] fn parse() { const CID: i64 = 1; - const FID: i64 = 1; + const FID: i64 = 2; + const IS: i64 = 3; + const G: i64 = 4; + const B: i64 = 5; let ufc = UnparsedFeedChannel { channel_id: CID, feed_id: FID, + initial_score: Some(IS), + gravity: Some(G), + boost: Some(B), }; let fc = ufc.parse().unwrap(); assert_eq!(fc.channel_id.0, CID); assert_eq!(fc.feed_id.0, FID); + assert_eq!(i64::from(fc.initial_score), IS); + assert_eq!(i64::from(fc.gravity), G); + assert_eq!(i64::from(fc.boost), B); } // FeedChannel Tests @@ -93,6 +126,9 @@ mod tests { let fc = FeedChannel { channel_id: channel.id(), feed_id: FeedId(1), // Fake Feed + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), }; let channel_from_fc = fc.get_channel(pool).await.unwrap(); @@ -110,14 +146,18 @@ mod tests { let fc = FeedChannel { channel_id: ChannelId(1), // Fake Channel feed_id: feed.id(), + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), }; let feed_from_fc = fc.get_feed(pool).await.unwrap(); assert_eq!(feed_from_fc.id(), feed.id()); } - + #[tokio::test] pub async fn add_item() { + let dt = get_datetime(); let adapter = setup_adapter().await; let pool = adapter.get_pool(); @@ -128,10 +168,13 @@ mod tests { let fc = FeedChannel { channel_id: channel.id(), feed_id: feed.id(), + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), }; let item = Item::get_or_create(pool, channel.id(), "item-guid").await.unwrap(); - fc.add_item(pool, &item).await.unwrap(); + fc.add_item_at(pool, &item, dt).await.unwrap(); let items = feed.get_items(pool, 1, 0).await.unwrap(); assert_eq!(items[0].id(), item.id()); diff --git a/koucha/src/score.rs b/koucha/src/score.rs index 4cdac60..6d6cba2 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -1,5 +1,6 @@ use chrono::{DateTime, Utc, TimeDelta}; use crate::{Result}; +use std::ops::{Add, Sub}; mod default { use crate::score::SECONDS_IN_A_DAY; @@ -12,57 +13,91 @@ mod default { const SECONDS_IN_A_DAY: i64 = 60 * 60 * 24; macro_rules! rich_i64 { - ($name:ident, $default:expr) => { - #[derive(PartialEq, Debug, Copy, Clone)] - pub struct $name(i64); - impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } - impl $name { - pub fn new(value: Option) -> Self { - Self(value.unwrap_or($default)) - } - } - }; + ($name:ident) => { + #[derive(PartialOrd, PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } + }; } -rich_i64!(Gravity, default::GRAVITY); -rich_i64!(Boost, default::BOOST); -pub struct UnparsedScore { +macro_rules! defaulting_i64 { + ($name:ident, $default:expr) => { + rich_i64!($name); + impl $name { + pub fn new(value: Option) -> Self { + Self(value.unwrap_or($default)) + } + } + }; +} + +macro_rules! addable_i64s { + ($lhs:ident, $rhs:ident) => { + impl Add<$rhs> for $lhs { + type Output = Self; + fn add(self, other: $rhs) -> Self::Output { Self(self.0 + other.0) } + } + } +} + +defaulting_i64!(Score, default::INITIAL_SCORE); +addable_i64s!(Score, Score); +addable_i64s!(Score, Boost); +impl Sub for Score { + type Output = Self; + fn sub(self, other: Boost) -> Self::Output { Self(self.0 - other.0) } +} +addable_i64s!(Score, GravityOverDuration); +defaulting_i64!(Boost, default::BOOST); +defaulting_i64!(Gravity, default::GRAVITY); +rich_i64!(GravityOverDuration); +impl Gravity { + fn over_duration( + &self, start: DateTime, end: DateTime + ) -> GravityOverDuration { + let elapsed_time = end.signed_duration_since(start); + GravityOverDuration( + self.0 * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) + ) + } +} +pub struct UnparsedTimedScore { pub value: i64, pub last_updated: DateTime, pub last_boosted: Option>, } -impl UnparsedScore { - pub fn parse(self) -> Score { +impl UnparsedTimedScore { + pub fn parse(self) -> TimedScore { match self.last_boosted { - None => Score::Decaying(DecayingScore { - value: self.value, + None => TimedScore::Decaying(DecayingScore { + value: Score(self.value), last_updated: self.last_updated, }), - Some(last_boosted) => Score::Boosted(BoostedScore { - value: self.value, + Some(last_boosted) => TimedScore::Boosted(BoostedScore { + value: Score(self.value), boosted_at: last_boosted, }), } } } -pub enum Score { +pub enum TimedScore { Decaying(DecayingScore), Boosted(BoostedScore), } -impl Score { +impl TimedScore { pub fn new() -> DecayingScore { - Self::new_with_initial(default::INITIAL_SCORE) + Self::new_with_initial(Score::new(None)) } - pub fn new_with_initial(initial_score: i64) -> DecayingScore { + pub fn new_with_initial(initial_score: Score) -> DecayingScore { Self::new_with_initial_and_time(initial_score, Utc::now()) } pub fn new_with_initial_and_time( - initial: i64, time: DateTime + initial: Score, time: DateTime ) -> DecayingScore { DecayingScore { value: initial, @@ -70,7 +105,7 @@ impl Score { } } - pub fn get_score(&self) -> i64 { + pub fn get_score(&self) -> Score { match self { Self::Decaying(s) => s.get_score(), Self::Boosted(b) => b.get_score(), @@ -83,16 +118,16 @@ impl Score { fn update_score_at_time(self, gravity: Gravity, time: DateTime) -> Self { match self { - Self::Decaying(d) => Score::Decaying( + Self::Decaying(d) => TimedScore::Decaying( d.apply_gravity_to_time(gravity, time) ), Self::Boosted(b) => { let try_unfrozen = b.try_unfreeze_at_time(time); match try_unfrozen { - Self::Decaying(s) => Score::Decaying( + Self::Decaying(s) => TimedScore::Decaying( s.apply_gravity_to_time(gravity, time) ), - Self::Boosted(b) => Score::Boosted(b), + Self::Boosted(b) => TimedScore::Boosted(b), } } } @@ -114,30 +149,26 @@ impl Score { } pub struct BoostedScore { - value: i64, + value: Score, boosted_at: DateTime, } pub struct DecayingScore { - value: i64, + value: Score, last_updated: DateTime, } impl DecayingScore { - fn get_score(&self) -> i64 { + fn get_score(&self) -> Score { self.value } fn apply_gravity_to_time( self, gravity: Gravity, update_time: DateTime ) -> Self { - let elapsed_time: TimeDelta = update_time.signed_duration_since(self.last_updated); - let new_value = if elapsed_time <= TimeDelta::zero() { self.value } else { - self.value + i64::from(gravity) * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) - }; Self { last_updated: update_time, - value: new_value, + value: self.value + gravity.over_duration(self.last_updated, update_time), } } @@ -147,33 +178,33 @@ impl DecayingScore { fn boost_at_time(self, boost: Boost, boost_time: DateTime) -> BoostedScore { BoostedScore { - value: self.value + i64::from(boost), + value: self.value + boost, boosted_at: boost_time, } } } impl BoostedScore { - fn get_score(&self) -> i64 { + fn get_score(&self) -> Score { self.value } pub fn unboost(self, boost: Boost) -> DecayingScore { DecayingScore { - value: self.value - i64::from(boost), + value: self.value - boost, last_updated: self.boosted_at, } } - fn try_unfreeze_at_time(self, update_time: DateTime) -> Score { + fn try_unfreeze_at_time(self, update_time: DateTime) -> TimedScore { let boost_end = self.boosted_at + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); if boost_end < update_time { - Score::Decaying(DecayingScore { + TimedScore::Decaying(DecayingScore { value: self.value, last_updated: boost_end, }) } else { - Score::Boosted(self) + TimedScore::Boosted(self) } } } @@ -199,7 +230,7 @@ mod tests { #[test] fn parse_decaying() { - let ups = UnparsedScore { + let ups = UnparsedTimedScore { value: 10, last_updated: get_datetime(), last_boosted: None, @@ -211,7 +242,7 @@ mod tests { #[test] fn parse_boosted() { let dt = get_datetime(); - let ups = UnparsedScore { + let ups = UnparsedTimedScore { value: 10, last_updated: dt, last_boosted: Some(dt), @@ -222,22 +253,24 @@ mod tests { #[test] fn new() { - let score = Score::new(); - assert_eq!(score.value, default::INITIAL_SCORE); + let score = TimedScore::new(); + assert_eq!(score.value, Score(default::INITIAL_SCORE)); } #[test] fn new_with_values() { let dt = get_datetime(); - let score = Score::new_with_initial_and_time(10, dt); - assert_eq!(score.value, 10); + let score = TimedScore::new_with_initial_and_time(Score(10), dt); + assert_eq!(score.value, Score(10)); assert_eq!(score.last_updated, dt); } #[test] fn update_score_stays_decaying() { let dt = get_datetime(); - let score = Score::Decaying(Score::new_with_initial_and_time(10, dt)); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); let gravity = Gravity::new(None); let dt2 = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); @@ -248,7 +281,9 @@ mod tests { #[test] fn update_score_stays_frozen() { let dt = get_datetime(); - let score = Score::Boosted(BoostedScore { value: 10, boosted_at: dt }); + let score = TimedScore::Boosted( + BoostedScore { value: Score(10), boosted_at: dt } + ); let gravity = Gravity::new(None); let dt2 = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); @@ -259,7 +294,9 @@ mod tests { #[test] fn update_score_thaws_and_decays() { let dt = get_datetime(); - let score = Score::Boosted(BoostedScore { value: 10, boosted_at: dt }); + let score = TimedScore::Boosted( + BoostedScore { value: Score(10), boosted_at: dt } + ); let gravity = Gravity::new(None); let dt2 = dt + TimeDelta::seconds( @@ -268,13 +305,15 @@ mod tests { let updated = score.update_score_at_time(gravity, dt2) .get_decaying().unwrap(); - assert!(updated.value < 10) + assert!(updated.value < Score(10)) } #[test] fn get_decaying_success() { let dt = get_datetime(); - let score = Score::Decaying(Score::new_with_initial_and_time(10, dt)); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); score.get_decaying().unwrap(); } @@ -283,7 +322,9 @@ mod tests { #[should_panic = "Attempted to get_boosted() of a decaying score"] fn get_boosted_failure() { let dt = get_datetime(); - let score = Score::Decaying(Score::new_with_initial_and_time(10, dt)); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); score.get_boosted().unwrap(); } @@ -293,8 +334,9 @@ mod tests { fn get_decaying_failure() { let dt = get_datetime(); let boost = Boost::new(None); - let score = Score::Boosted( - Score::new_with_initial_and_time(10, dt).boost_at_time(boost, dt) + let score = TimedScore::Boosted( + TimedScore::new_with_initial_and_time(Score(10), dt) + .boost_at_time(boost, dt) ); score.get_decaying().unwrap(); @@ -304,8 +346,9 @@ mod tests { fn get_boosted_success() { let dt = get_datetime(); let boost = Boost::new(None); - let score = Score::Boosted( - Score::new_with_initial_and_time(10, dt).boost_at_time(boost, dt) + let score = TimedScore::Boosted( + TimedScore::new_with_initial_and_time(Score(10), dt) + .boost_at_time(boost, dt) ); score.get_boosted().unwrap(); @@ -316,37 +359,37 @@ mod tests { #[test] fn apply_gravity_to_future() { let dt = get_datetime(); - let score = DecayingScore { value: 10, last_updated: dt }; + let score = DecayingScore { value: Score(10), last_updated: dt }; let future = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); let gravity = Gravity::new(None); let updated = score.apply_gravity_to_time(gravity, future); - assert_eq!(updated.value, 10 + default::GRAVITY); + assert!(updated.value < Score(10)); assert_eq!(updated.last_updated, future); } - + #[test] fn apply_gravity_to_past() { let dt = get_datetime(); - let score = DecayingScore { value: 10, last_updated: dt }; + let score = DecayingScore { value: Score(10), last_updated: dt }; let past = dt - TimeDelta::seconds(SECONDS_IN_A_DAY); let gravity = Gravity::new(None); let updated = score.apply_gravity_to_time(gravity, past); - assert_eq!(updated.value, 10); + assert!(updated.value > Score(10)); assert_eq!(updated.last_updated, past); } #[test] fn boost() { let dt = get_datetime(); - let score = DecayingScore { value: 10, last_updated: dt }; + let score = DecayingScore { value: Score(10), last_updated: dt }; let boost = Boost::new(None); let boosted = score.boost_at_time(boost, dt); - assert_eq!(boosted.value, 10 + default::BOOST); + assert_eq!(boosted.value, Score(10) + Boost(default::BOOST)); assert_eq!(boosted.boosted_at, dt); } @@ -355,19 +398,19 @@ mod tests { #[test] fn unboost() { let dt = get_datetime(); - let score = DecayingScore { value: 10, last_updated: dt }; + let score = DecayingScore { value: Score(10), last_updated: dt }; let boost = Boost::new(None); let boosted = score.boost_at_time(boost, dt); let unboosted = boosted.unboost(boost); - assert_eq!(unboosted.value, 10); + assert_eq!(unboosted.value, Score(10)); assert_eq!(unboosted.last_updated, dt); } #[test] fn boosted_stays_frozen() { let dt = get_datetime(); - let score = BoostedScore { value: 10, boosted_at: dt }; + let score = BoostedScore { value: Score(10), boosted_at: dt }; let last_second = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); @@ -377,7 +420,7 @@ mod tests { #[test] fn boosted_thaws() { let dt = get_datetime(); - let score = BoostedScore { value: 10, boosted_at: dt }; + let score = BoostedScore { value: Score(10), boosted_at: dt }; let first_second = dt + TimeDelta::days(default::BOOST_FREEZE_IN_SECONDS+1); From f2e00afbb95955c1a29b192490409561f56e6b98 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Wed, 4 Feb 2026 13:52:22 -0800 Subject: [PATCH 21/32] Adding fetch_item, but need to expand what an ID can be --- koucha/src/db.rs | 2 ++ koucha/src/db/feed_channel.rs | 1 - koucha/src/db/feed_item.rs | 56 +++++++++++++++++++++++++++++++++++ koucha/src/fetch.rs | 2 +- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 koucha/src/db/feed_item.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs index 2456bd9..6914cfa 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -4,6 +4,8 @@ mod feed; pub use feed::Feed; mod feed_channel; pub use feed_channel::FeedChannel; +mod feed_item; +pub use feed_item::FeedItem; mod channel; pub use channel::Channel; mod item; diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs index 0640555..f8a3870 100644 --- a/koucha/src/db/feed_channel.rs +++ b/koucha/src/db/feed_channel.rs @@ -72,7 +72,6 @@ impl FeedChannel { ).execute(&pool.0).await?; Ok(()) } - } #[cfg(test)] diff --git a/koucha/src/db/feed_item.rs b/koucha/src/db/feed_item.rs new file mode 100644 index 0000000..052e8a3 --- /dev/null +++ b/koucha/src/db/feed_item.rs @@ -0,0 +1,56 @@ +use chrono::{DateTime, Utc}; +use crate::{ + Result, + AdapterPool, + db::{ + ItemId, + FeedId, + }, + score::{ + TimedScore, + UnparsedTimedScore, + }, +}; + +pub struct UnparsedFeedItem { + pub item_id: i64, + pub feed_id: i64, + pub score: i64, + pub last_updated: String, + pub boosted_at: Option, +} +impl UnparsedFeedItem { + pub fn parse(self) -> Result { + Ok(FeedItem { + item_id: ItemId(self.item_id), + feed_id: FeedId(self.feed_id), + score: (UnparsedTimedScore { + value: self.score, + last_updated: DateTime::parse_from_rfc2822(&self.last_updated)? + .with_timezone(&Utc), + last_boosted: self.boosted_at.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), + }).parse(), + }) + } +} + +pub struct FeedItem { + item_id: ItemId, + feed_id: FeedId, + score: TimedScore, +} + +impl FeedItem { + // async fn boost(pool: &AdapterPool, boost: Boost) -> Result<()> { + // self.boost_at(pool, boost, Utc::now()).await + // } + // + // async fn boost_at( + // &self, pool: &AdapterPool, boost: Boost, boost_at: DateTime + // ) -> Result<()> { + // + // } +} diff --git a/koucha/src/fetch.rs b/koucha/src/fetch.rs index 532b4fe..a25b9de 100644 --- a/koucha/src/fetch.rs +++ b/koucha/src/fetch.rs @@ -1,6 +1,6 @@ use crate::{ Result, - db::Channel, + db::{Channel, ChannelId}, AdapterClient, }; use reqwest::Url; From c3d9dff83f79cbf59b5cfc256ab6efe50acec632 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Wed, 4 Feb 2026 13:59:54 -0800 Subject: [PATCH 22/32] Remove from from db_ids --- koucha/src/db.rs | 9 ++++----- koucha/src/db/channel.rs | 5 +---- koucha/src/db/feed.rs | 6 ++---- koucha/src/db/feed_channel.rs | 5 ++--- koucha/src/db/item.rs | 3 +-- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/koucha/src/db.rs b/koucha/src/db.rs index 6914cfa..d103e86 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -12,11 +12,10 @@ mod item; pub use item::Item; macro_rules! define_id { - ($name:ident) => { - #[derive(PartialEq, Debug, Copy, Clone)] - pub struct $name(i64); - impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } - }; + ($name:ident) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + }; } define_id!(UserId); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 6df59fb..d7dfca9 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -245,10 +245,7 @@ mod tests { let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap(); let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap(); - assert_eq!( - i64::from(channel1.id()), - i64::from(channel2.id()) - ); + assert_eq!(channel1.id(), channel2.id()); } #[tokio::test] diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index a769b1b..f3a8559 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -49,13 +49,12 @@ impl Feed { pub async fn create( pool: &AdapterPool, user_id: UserId, title: &str ) -> Result { - let int_id = i64::from(user_id); let new_feed = sqlx::query_as!( UnparsedFeed, "INSERT INTO feeds (user_id, title) VALUES (?, ?) RETURNING id as `id!`, title", - int_id, title + user_id.0, title ).fetch_one(&pool.0).await?.parse(); new_feed @@ -75,11 +74,10 @@ impl Feed { pub async fn add_channel( &self, pool: &AdapterPool, channel_id: ChannelId ) -> Result<()> { - let int_channel_id = i64::from(channel_id); sqlx::query!( "INSERT INTO feed_channels (feed_id, channel_id) VALUES (?, ?)", - self.id.0, int_channel_id + self.id.0, channel_id.0 ).execute(&pool.0).await?; Ok(()) diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs index f8a3870..27e39f9 100644 --- a/koucha/src/db/feed_channel.rs +++ b/koucha/src/db/feed_channel.rs @@ -60,15 +60,14 @@ impl FeedChannel { async fn add_item_at( &self, pool: &AdapterPool, item: &Item, add_at: DateTime ) -> Result<()> { - let int_item_id = i64::from(item.id()); - let int_feed_id = i64::from(self.feed_id); + let int_item_id = item.id().0; let int_initial_score = i64::from(self.initial_score); let string_last_updated = add_at.to_rfc2822(); sqlx::query!( "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated) VALUES (?, ?, ?, ?)", - int_feed_id, int_item_id, int_initial_score, string_last_updated + self.feed_id.0, int_item_id, int_initial_score, string_last_updated ).execute(&pool.0).await?; Ok(()) } diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs index cb25331..a910a14 100644 --- a/koucha/src/db/item.rs +++ b/koucha/src/db/item.rs @@ -58,7 +58,6 @@ impl Item { pub async fn get_or_create( pool: &AdapterPool, from_channel: ChannelId, guid: &str ) -> Result { - let int_channel_id = i64::from(from_channel); let item = sqlx::query_as!( UnparsedItem, @@ -67,7 +66,7 @@ impl Item { ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id RETURNING id as `id!`, channel_id, fetched_at, title, description, content", - int_channel_id, guid + from_channel.0, guid ).fetch_one(&pool.0).await?.parse(); item From f0a4e12f2b4a70e6d5cd3e834c98350198ac54d9 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Wed, 4 Feb 2026 15:49:55 -0800 Subject: [PATCH 23/32] Convert to keys and setup feed_item --- koucha/src/db.rs | 19 ++++++++---- koucha/src/db/channel.rs | 10 +++---- koucha/src/db/feed.rs | 20 ++++++------- koucha/src/db/feed_channel.rs | 18 ++++++------ koucha/src/db/feed_item.rs | 55 +++++++++++++++++++++++++---------- koucha/src/db/item.rs | 18 ++++++------ koucha/src/db/user.rs | 14 ++++----- koucha/src/score.rs | 18 ++++++++++++ 8 files changed, 111 insertions(+), 61 deletions(-) diff --git a/koucha/src/db.rs b/koucha/src/db.rs index d103e86..cea05ac 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -11,14 +11,23 @@ pub use channel::Channel; mod item; pub use item::Item; -macro_rules! define_id { +macro_rules! define_key { ($name:ident) => { #[derive(PartialEq, Debug, Copy, Clone)] pub struct $name(i64); }; + + ($name:ident, $($field:ident),* $(,)?) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name { + $($field: i64),* + } + }; } -define_id!(UserId); -define_id!(FeedId); -define_id!(ChannelId); -define_id!(ItemId); +define_key!(UserKey); +define_key!(FeedKey); +define_key!(FeedChannelKey, feed_id, channel_id); +define_key!(FeedItemKey, feed_id, item_id); +define_key!(ChannelKey); +define_key!(ItemKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index d7dfca9..b79454f 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -4,7 +4,7 @@ use crate::{ Result, AdapterPool, db::{ - ChannelId, + ChannelKey, Item, FeedChannel, feed_channel::UnparsedFeedChannel, @@ -23,7 +23,7 @@ pub struct UnparsedChannel { impl UnparsedChannel { pub fn parse(self) -> Result { Ok(Channel { - id: ChannelId(self.id), + id: ChannelKey(self.id), title: self.title, link: Url::parse(&self.link)?, description: self.description, @@ -36,7 +36,7 @@ impl UnparsedChannel { } pub struct Channel { - id: ChannelId, + id: ChannelKey, title: String, link: Url, description: Option, @@ -44,7 +44,7 @@ pub struct Channel { } impl Channel { - pub fn id(&self) -> ChannelId { self.id } + pub fn id(&self) -> ChannelKey { self.id } pub fn title(&self) -> &str { &self.title } pub fn link(&self) -> &Url { &self.link } pub fn description(&self) -> Option<&str> { self.description.as_deref() } @@ -59,7 +59,7 @@ impl Channel { channels } - pub async fn get(pool: &AdapterPool, id: ChannelId) -> Result { + pub async fn get(pool: &AdapterPool, id: ChannelKey) -> Result { let channel: Result = sqlx::query_as!( UnparsedChannel, "SELECT id, title, link, description, last_fetched diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index f3a8559..c3c95d1 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -3,10 +3,10 @@ use crate::{ Result, db::{ Channel, - ChannelId, - FeedId, + ChannelKey, + FeedKey, Item, - UserId, + UserKey, channel::UnparsedChannel, item::UnparsedItem, }, @@ -19,23 +19,23 @@ pub struct UnparsedFeed { impl UnparsedFeed { pub fn parse(self) -> Result { Ok(Feed { - id: FeedId(self.id), + id: FeedKey(self.id), title: self.title, }) } } pub struct Feed { - id: FeedId, + id: FeedKey, title: String, } impl Feed { - pub fn id(&self) -> FeedId { self.id } + pub fn id(&self) -> FeedKey { self.id } pub fn title(&self) -> &str { &self.title } pub async fn get( - pool: &AdapterPool, id: FeedId + pool: &AdapterPool, id: FeedKey ) -> Result { let feed = sqlx::query_as!( UnparsedFeed, @@ -47,7 +47,7 @@ impl Feed { } pub async fn create( - pool: &AdapterPool, user_id: UserId, title: &str + pool: &AdapterPool, user_id: UserKey, title: &str ) -> Result { let new_feed = sqlx::query_as!( UnparsedFeed, @@ -61,7 +61,7 @@ impl Feed { } pub async fn update_title( - pool: &AdapterPool, id: FeedId, new_title: &str + pool: &AdapterPool, id: FeedKey, new_title: &str ) -> Result<()> { sqlx::query!( "UPDATE feeds SET title = ? WHERE id = ?", @@ -72,7 +72,7 @@ impl Feed { } pub async fn add_channel( - &self, pool: &AdapterPool, channel_id: ChannelId + &self, pool: &AdapterPool, channel_id: ChannelKey ) -> Result<()> { sqlx::query!( "INSERT INTO feed_channels (feed_id, channel_id) diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs index 27e39f9..d736c2d 100644 --- a/koucha/src/db/feed_channel.rs +++ b/koucha/src/db/feed_channel.rs @@ -3,9 +3,9 @@ use crate::{ AdapterPool, db::{ Channel, - ChannelId, + ChannelKey, Feed, - FeedId, + FeedKey, Item, }, score::{ @@ -26,8 +26,8 @@ pub struct UnparsedFeedChannel { impl UnparsedFeedChannel { pub fn parse(self) -> Result { Ok(FeedChannel { - channel_id: ChannelId(self.channel_id), - feed_id: FeedId(self.feed_id), + channel_id: ChannelKey(self.channel_id), + feed_id: FeedKey(self.feed_id), initial_score: Score::new(self.initial_score), gravity: Gravity::new(self.gravity), boost: Boost::new(self.boost), @@ -36,8 +36,8 @@ impl UnparsedFeedChannel { } pub struct FeedChannel { - channel_id: ChannelId, - feed_id: FeedId, + channel_id: ChannelKey, + feed_id: FeedKey, initial_score: Score, gravity: Gravity, boost: Boost, @@ -80,7 +80,7 @@ mod tests { use crate::{ db::{ Channel, - FeedId, + FeedKey, User }, test_utils::{ @@ -123,7 +123,7 @@ mod tests { let fc = FeedChannel { channel_id: channel.id(), - feed_id: FeedId(1), // Fake Feed + feed_id: FeedKey(1), // Fake Feed initial_score: Score::new(None), gravity: Gravity::new(None), boost: Boost::new(None), @@ -142,7 +142,7 @@ mod tests { let feed = Feed::create(pool, user.id(), "My Feed").await.unwrap(); let fc = FeedChannel { - channel_id: ChannelId(1), // Fake Channel + channel_id: ChannelKey(1), // Fake Channel feed_id: feed.id(), initial_score: Score::new(None), gravity: Gravity::new(None), diff --git a/koucha/src/db/feed_item.rs b/koucha/src/db/feed_item.rs index 052e8a3..ba1c29a 100644 --- a/koucha/src/db/feed_item.rs +++ b/koucha/src/db/feed_item.rs @@ -3,12 +3,11 @@ use crate::{ Result, AdapterPool, db::{ - ItemId, - FeedId, + FeedItemKey, }, score::{ TimedScore, - UnparsedTimedScore, + UnparsedTimedScore }, }; @@ -22,8 +21,10 @@ pub struct UnparsedFeedItem { impl UnparsedFeedItem { pub fn parse(self) -> Result { Ok(FeedItem { - item_id: ItemId(self.item_id), - feed_id: FeedId(self.feed_id), + key: FeedItemKey { + feed_id: self.feed_id, + item_id: self.item_id, + }, score: (UnparsedTimedScore { value: self.score, last_updated: DateTime::parse_from_rfc2822(&self.last_updated)? @@ -38,19 +39,41 @@ impl UnparsedFeedItem { } pub struct FeedItem { - item_id: ItemId, - feed_id: FeedId, + key: FeedItemKey, score: TimedScore, } impl FeedItem { - // async fn boost(pool: &AdapterPool, boost: Boost) -> Result<()> { - // self.boost_at(pool, boost, Utc::now()).await - // } - // - // async fn boost_at( - // &self, pool: &AdapterPool, boost: Boost, boost_at: DateTime - // ) -> Result<()> { - // - // } + pub fn key(&self) -> FeedItemKey { self.key } + pub fn score(&self) -> TimedScore { self.score.clone() } + + pub async fn archive( + &self, pool: &AdapterPool + ) -> Result<()> { + sqlx::query!( + "UPDATE feed_items + SET archived = ? + WHERE feed_id = ? AND item_id = ?", + true, self.key.feed_id, self.key.item_id + ).execute(&pool.0).await?; + + Ok(()) + } + + pub async fn update_score( + pool: &AdapterPool, key: FeedItemKey, new_score: TimedScore + ) -> Result<()> { + let unparsed_score = UnparsedTimedScore::unparse(new_score); + let last_updated = unparsed_score.last_updated.to_rfc2822(); + let boosted_at = unparsed_score.last_boosted.map(|lb| lb.to_rfc2822()); + + sqlx::query!( + "UPDATE feed_items + SET score = ?, last_updated = ?, boosted_at = ? + WHERE feed_id = ? AND item_id = ?", + unparsed_score.value, last_updated, boosted_at, key.feed_id, key.item_id + ).execute(&pool.0).await?; + + Ok(()) + } } diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs index a910a14..e3486d4 100644 --- a/koucha/src/db/item.rs +++ b/koucha/src/db/item.rs @@ -2,8 +2,8 @@ use crate::{ Result, AdapterPool, db::{ - ChannelId, - ItemId, + ChannelKey, + ItemKey, }, fetch::FetchedRSSItem, }; @@ -22,8 +22,8 @@ pub struct UnparsedItem { impl UnparsedItem { pub fn parse(self) -> Result { Ok(Item { - id: ItemId(self.id), - channel_id: ChannelId(self.channel_id), + id: ItemKey(self.id), + channel_id: ChannelKey(self.channel_id), fetched_at: match self.fetched_at { Some(dt_str) => Some(DateTime::parse_from_rfc2822(&dt_str)? .with_timezone(&Utc)), @@ -38,8 +38,8 @@ impl UnparsedItem { } pub struct Item { - id: ItemId, - channel_id: ChannelId, + id: ItemKey, + channel_id: ChannelKey, #[allow(dead_code)] // TODO: Use for score decay calculations later fetched_at: Option>, @@ -49,14 +49,14 @@ pub struct Item { } impl Item { - pub fn id(&self) -> ItemId { self.id } - pub fn channel(&self) -> ChannelId { self.channel_id } + pub fn id(&self) -> ItemKey { self.id } + pub fn channel(&self) -> ChannelKey { self.channel_id } pub fn title(&self) -> Option<&str> { self.title.as_deref() } pub fn description(&self) -> Option<&str> { self.description.as_deref() } pub fn content(&self) -> Option<&str> { self.content.as_deref() } pub async fn get_or_create( - pool: &AdapterPool, from_channel: ChannelId, guid: &str + pool: &AdapterPool, from_channel: ChannelKey, guid: &str ) -> Result { let item = sqlx::query_as!( diff --git a/koucha/src/db/user.rs b/koucha/src/db/user.rs index 63f24d8..ef7ba51 100644 --- a/koucha/src/db/user.rs +++ b/koucha/src/db/user.rs @@ -2,7 +2,7 @@ use crate::{ Result, AdapterPool, db::{ - UserId, + UserKey, Feed, feed::UnparsedFeed, }, @@ -15,22 +15,22 @@ pub struct UnparsedUser { impl UnparsedUser { pub fn parse(self) -> Result { Ok(User { - id: UserId(self.id), + id: UserKey(self.id), name: self.name }) } } pub struct User { - id: UserId, + id: UserKey, name: String, } impl User { - pub fn id(&self) -> UserId { self.id } + pub fn id(&self) -> UserKey { self.id } pub fn name(&self) -> &str { &self.name } - pub async fn get(pool: &AdapterPool, id: UserId) -> Result { + pub async fn get(pool: &AdapterPool, id: UserKey) -> Result { let user = sqlx::query_as!( UnparsedUser, "SELECT id, name FROM users WHERE id = ?", @@ -58,13 +58,13 @@ impl User { ).fetch_one(&pool.0).await?; Ok(Self { - id: UserId(result.id), + id: UserKey(result.id), name: result.name, }) } pub async fn update_name( - pool: &AdapterPool, id: UserId, new_name: &str + pool: &AdapterPool, id: UserKey, new_name: &str ) -> Result<()> { sqlx::query!( "UPDATE users SET name = ? WHERE id = ?", diff --git a/koucha/src/score.rs b/koucha/src/score.rs index 6d6cba2..754ca17 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -80,8 +80,24 @@ impl UnparsedTimedScore { }), } } + + pub fn unparse(ts: TimedScore) -> Self { + match ts { + TimedScore::Decaying(ds) => UnparsedTimedScore { + value: ds.value.into(), + last_updated: ds.last_updated, + last_boosted: None, + }, + TimedScore::Boosted(bs) => UnparsedTimedScore { + value: bs.value.into(), + last_updated: bs.boosted_at, + last_boosted: Some(bs.boosted_at), + }, + } + } } +#[derive(Clone)] pub enum TimedScore { Decaying(DecayingScore), Boosted(BoostedScore), @@ -148,11 +164,13 @@ impl TimedScore { } } +#[derive(Clone)] pub struct BoostedScore { value: Score, boosted_at: DateTime, } +#[derive(Clone)] pub struct DecayingScore { value: Score, last_updated: DateTime, From 3654232dd6924fac0f42065e5eb08c0918101ed4 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 11:22:20 -0800 Subject: [PATCH 24/32] feed_item tests --- koucha/src/db/feed_item.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/koucha/src/db/feed_item.rs b/koucha/src/db/feed_item.rs index ba1c29a..8c96b8a 100644 --- a/koucha/src/db/feed_item.rs +++ b/koucha/src/db/feed_item.rs @@ -77,3 +77,25 @@ impl FeedItem { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::get_datetime; + + #[test] + fn parse_feed_item() { + let dt = get_datetime(); + let upi = UnparsedFeedItem { + item_id: 1, + feed_id: 2, + score: 5, + last_updated: dt.to_string(), + boosted_at: None, + }; + + let fi = upi.parse().unwrap(); + assert_eq!(fi.key.item_id, 1); + assert_eq!(fi.key.feed_id, 2); + } +} From a42853ac5a87daa739e03519f314db4e135c8c4d Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 12:05:43 -0800 Subject: [PATCH 25/32] score, initialize core functionality and types Adds Chrono package Adds a "Result" type to lib.rs creates helpful type aliases for Score, Boost, and Gravity. Creates a "TimedScore" which is a value and time data for calculating score over time. There are two forms of this, Boosted and Decaying. Since a Score can either be decaying over time or have been boosted recently and be kept from decaying for some time. Also implements a BoostedScore and a DecayingScore, which are both TimedScores which represent the different states. These are important because you can't boost a BoostedScore for instance. --- koucha/Cargo.lock | 507 ++++++++++++++++++++++++++++++++++++++++++++ koucha/Cargo.toml | 2 + koucha/src/lib.rs | 5 + koucha/src/score.rs | 193 +++++++++++++++++ 4 files changed, 707 insertions(+) create mode 100644 koucha/src/score.rs diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index 476c80f..cfc34e4 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -2,6 +2,513 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "js-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "koucha" version = "0.1.0" +dependencies = [ + "chrono", + "tokio", +] + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index b58c658..fbf4602 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -4,3 +4,5 @@ version = "0.1.0" edition = "2024" [dependencies] +tokio = { version = "1.49.0", features = ["full"] } +chrono = "0.4.43" diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index e69de29..ceed6cb 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -0,0 +1,5 @@ +use std::error::Error; + +type Result = std::result::Result>; + +pub mod score; diff --git a/koucha/src/score.rs b/koucha/src/score.rs new file mode 100644 index 0000000..8b27b09 --- /dev/null +++ b/koucha/src/score.rs @@ -0,0 +1,193 @@ +use chrono::{DateTime, Utc, TimeDelta}; +use crate::{Result}; +use std::ops::{Add, Sub}; + +mod default { + use crate::score::SECONDS_IN_A_DAY; + + pub const INITIAL_SCORE: i64 = 70; + pub const GRAVITY: i64 = -10; + pub const BOOST: i64 = 12; + pub const BOOST_FREEZE_IN_SECONDS: i64 = SECONDS_IN_A_DAY; +} +const SECONDS_IN_A_DAY: i64 = 60 * 60 * 24; + +macro_rules! rich_i64 { + ($name:ident) => { + #[derive(PartialOrd, PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } + }; +} + +macro_rules! defaulting_i64 { + ($name:ident, $default:expr) => { + rich_i64!($name); + impl $name { + pub fn new(value: Option) -> Self { + Self(value.unwrap_or($default)) + } + } + }; +} + +macro_rules! addable_i64s { + ($lhs:ident, $rhs:ident) => { + impl Add<$rhs> for $lhs { + type Output = Self; + fn add(self, other: $rhs) -> Self::Output { Self(self.0 + other.0) } + } + } +} + +defaulting_i64!(Score, default::INITIAL_SCORE); +addable_i64s!(Score, Score); +addable_i64s!(Score, Boost); +impl Sub for Score { + type Output = Self; + fn sub(self, other: Boost) -> Self::Output { Self(self.0 - other.0) } +} +addable_i64s!(Score, GravityOverDuration); +defaulting_i64!(Boost, default::BOOST); +defaulting_i64!(Gravity, default::GRAVITY); +rich_i64!(GravityOverDuration); +impl Gravity { + fn over_duration( + &self, start: DateTime, end: DateTime + ) -> GravityOverDuration { + let elapsed_time = end.signed_duration_since(start); + GravityOverDuration( + self.0 * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) + ) + } +} + +#[derive(Clone)] +pub enum TimedScore { + Decaying(DecayingScore), + Boosted(BoostedScore), +} + +impl TimedScore { + pub fn new() -> DecayingScore { + Self::new_with_initial(Score::new(None)) + } + + pub fn new_with_initial(initial_score: Score) -> DecayingScore { + Self::new_with_initial_and_time(initial_score, Utc::now()) + } + + pub fn new_with_initial_and_time( + initial: Score, time: DateTime + ) -> DecayingScore { + DecayingScore { + value: initial, + last_updated: time, + } + } + + pub fn get_score(&self) -> Score { + match self { + Self::Decaying(s) => s.get_score(), + Self::Boosted(b) => b.get_score(), + } + } + + pub fn update_score(self, gravity: Gravity) -> Self { + self.update_score_at_time(gravity, Utc::now()) + } + + fn update_score_at_time(self, gravity: Gravity, time: DateTime) -> Self { + match self { + Self::Decaying(d) => TimedScore::Decaying( + d.apply_gravity_to_time(gravity, time) + ), + Self::Boosted(b) => { + let try_unfrozen = b.try_unfreeze_at_time(time); + match try_unfrozen { + Self::Decaying(s) => TimedScore::Decaying( + s.apply_gravity_to_time(gravity, time) + ), + Self::Boosted(b) => TimedScore::Boosted(b), + } + } + } + } + + pub fn get_decaying(self) -> Result { + match self { + Self::Decaying(s) => Ok(s), + Self::Boosted(_) => Err("Attempted to get_decaying() of a boosted score".into()), + } + } + + pub fn get_boosted(self) -> Result { + match self { + Self::Decaying(_) => Err("Attempted to get_boosted() of a decaying score".into()), + Self::Boosted(b) => Ok(b), + } + } +} + +#[derive(Clone)] +pub struct BoostedScore { + value: Score, + boosted_at: DateTime, +} + +#[derive(Clone)] +pub struct DecayingScore { + value: Score, + last_updated: DateTime, +} + +impl DecayingScore { + fn get_score(&self) -> Score { + self.value + } + + fn apply_gravity_to_time( + self, gravity: Gravity, update_time: DateTime + ) -> Self { + Self { + last_updated: update_time, + value: self.value + gravity.over_duration(self.last_updated, update_time), + } + } + + pub fn boost(self, boost: Boost) -> BoostedScore { + self.boost_at_time(boost, Utc::now()) + } + + fn boost_at_time(self, boost: Boost, boost_time: DateTime) -> BoostedScore { + BoostedScore { + value: self.value + boost, + boosted_at: boost_time, + } + } +} + +impl BoostedScore { + fn get_score(&self) -> Score { + self.value + } + + pub fn unboost(self, boost: Boost) -> DecayingScore { + DecayingScore { + value: self.value - boost, + last_updated: self.boosted_at, + } + } + + fn try_unfreeze_at_time(self, update_time: DateTime) -> TimedScore { + let boost_end = self.boosted_at + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + if boost_end < update_time { + TimedScore::Decaying(DecayingScore { + value: self.value, + last_updated: boost_end, + }) + } else { + TimedScore::Boosted(self) + } + } +} From 6702f976cb83ea3c0d06dcfb9a6748f4c1818d30 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 12:23:27 -0800 Subject: [PATCH 26/32] Add sqlx, add Adapter, create initial schema Adds SQLX for database management, and an Adapter interface for interacting with it. Through the type "AdapterPool" Creates an initial_schema with everything I think I'll need. --- flake.lock | 8 +- flake.nix | 4 +- koucha/.gitignore | 1 + koucha/Cargo.lock | 1419 ++++++++++++++++- koucha/Cargo.toml | 1 + .../20260115003047_initial_schema.sql | 62 + koucha/src/lib.rs | 33 + 7 files changed, 1514 insertions(+), 14 deletions(-) create mode 100644 koucha/migrations/20260115003047_initial_schema.sql diff --git a/flake.lock b/flake.lock index 2972d8a..c4fa525 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1768127708, - "narHash": "sha256-1Sm77VfZh3mU0F5OqKABNLWxOuDeHIlcFjsXeeiPazs=", + "lastModified": 1769933782, + "narHash": "sha256-GlZemJ2dxhXMMq6TNyt588OFv4/jIt3J1QVBO9MspBE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ffbc9f8cbaacfb331b6017d5a5abb21a492c9a38", + "rev": "64728753f1a42c81c5688a136a6bee173665acc9", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixos-25.11-small", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index c3fa77f..f48d72e 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Koucha rust flake"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11-small"; }; outputs = { self, nixpkgs }: @@ -24,6 +24,8 @@ rustc cargo rust-analyzer + + sqlx-cli ]; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; diff --git a/koucha/.gitignore b/koucha/.gitignore index ea8c4bf..6dfb7e0 100644 --- a/koucha/.gitignore +++ b/koucha/.gitignore @@ -1 +1,2 @@ +*.db /target diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index cfc34e4..ff859af 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -11,17 +17,50 @@ dependencies = [ "libc", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bitflags" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] [[package]] name = "bumpalo" @@ -29,6 +68,12 @@ version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.11.1" @@ -64,12 +109,131 @@ dependencies = [ "windows-link", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "errno" version = "0.3.14" @@ -80,12 +244,218 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -110,6 +480,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + [[package]] name = "js-sys" version = "0.3.85" @@ -125,15 +613,59 @@ name = "koucha" version = "0.1.0" dependencies = [ "chrono", + "sqlx", "tokio", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + [[package]] name = "libc" version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags", + "libc", + "redox_syscall 0.7.0", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + [[package]] name = "lock_api" version = "0.4.14" @@ -149,6 +681,22 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + [[package]] name = "mio" version = "1.1.1" @@ -160,6 +708,42 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -167,6 +751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -175,6 +760,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -193,17 +784,83 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", "windows-link", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + [[package]] name = "pin-project-lite" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -222,6 +879,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -231,18 +918,130 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustversion" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" +[[package]] +name = "ryu" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "1.3.0" @@ -259,11 +1058,30 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -275,6 +1093,236 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.114" @@ -286,6 +1334,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.49.0" @@ -314,18 +1418,124 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.108" @@ -371,6 +1581,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -430,13 +1650,22 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets", + "windows-targets 0.53.5", ] [[package]] @@ -448,6 +1677,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + [[package]] name = "windows-targets" version = "0.53.5" @@ -455,28 +1699,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.53.1" @@ -489,26 +1751,165 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57cf3aa6855b23711ee9852dfc97dfaa51c45feaba5b645d0c777414d494a961" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a616990af1a287837c4fe6596ad77ef57948f787e46ce28e166facc0cc1cb75" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff05f8caa9038894637571ae6b9e29466c1f4f829d26c9b28f869a29cbe3445" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index fbf4602..3da8f35 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -5,4 +5,5 @@ edition = "2024" [dependencies] tokio = { version = "1.49.0", features = ["full"] } +sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.43" diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql new file mode 100644 index 0000000..b863eee --- /dev/null +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -0,0 +1,62 @@ +-- Add migration script here + +PRAGMA foreign_keys = ON; + +CREATE TABLE users ( + id INTEGER PRIMARY KEY, + name TEXT UNIQUE NOT NULL +); + +CREATE TABLE channels ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL, + link TEXT UNIQUE NOT NULL, + description TEXT, + last_fetched TEXT +); + +CREATE TABLE items ( + id INTEGER PRIMARY KEY, + channel_id INTEGER NOT NULL, + guid TEXT NOT NULL, + + fetched_at TEXT, + title TEXT, + description TEXT, + content TEXT, + + UNIQUE(channel_id, guid), + FOREIGN KEY (channel_id) REFERENCES channels(id) +); + +CREATE TABLE feeds ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + title TEXT NOT NULL, + FOREIGN KEY (user_id) REFERENCES users(id) +); + +CREATE TABLE feed_channels ( + feed_id INTEGER NOT NULL, + channel_id INTEGER NOT NULL, + initial_score INTEGER, + gravity INTEGER, + boost INTEGER, + PRIMARY KEY (feed_id, channel_id), + FOREIGN KEY (feed_id) REFERENCES feeds(id), + FOREIGN KEY (channel_id) REFERENCES channels(id) +); + +CREATE TABLE feed_items ( + item_id INTEGER NOT NULL, + feed_id INTEGER NOT NULL, + score INTEGER NOT NULL, + last_updated TEXT NOT NULL, + boosted_at TEXT, + archived BOOLEAN DEFAULT FALSE, + PRIMARY KEY (item_id, feed_id), + FOREIGN KEY (feed_id) REFERENCES feeds(id), + FOREIGN KEY (item_id) REFERENCES items(id) +); +CREATE INDEX idx_feed_items_score +ON feed_items(feed_id, archived, score DESC); diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index ceed6cb..b0aef7d 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,3 +3,36 @@ use std::error::Error; type Result = std::result::Result>; pub mod score; +pub struct AdapterPool(sqlx::SqlitePool); +pub struct AdapterBuilder { + database_url: String, +} + +impl AdapterBuilder { + pub fn new() -> Self { + Self { + database_url: "sqlite:test.db".to_string(), + } + } + + pub fn database_url(mut self, url: &str) -> Self { + self.database_url = url.to_string(); + self + } + + pub async fn create(self) -> Result { + let db = sqlx::sqlite::SqlitePoolOptions::new() + .connect(&self.database_url).await?; + sqlx::migrate!().run(&db).await?; + + Ok(Adapter { db: AdapterPool(db) }) + } +} + +pub struct Adapter { + db: AdapterPool, +} + +impl Adapter { + pub fn get_pool(&self) -> &AdapterPool { &self.db } +} From eb21bf0d515a3a98974f2f6195fbe0a34b2e8fab Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 12:36:28 -0800 Subject: [PATCH 27/32] score+test, Tests for a42853a & test_utils mod Tests for all the core functionality implemented to score in a42853a. Optimistically adding a test_utils mod for shared test code --- koucha/src/lib.rs | 4 + koucha/src/score.rs | 196 +++++++++++++++++++++++++++++++++++++++ koucha/src/test_utils.rs | 11 +++ 3 files changed, 211 insertions(+) create mode 100644 koucha/src/test_utils.rs diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index b0aef7d..3bf607b 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,6 +3,10 @@ use std::error::Error; type Result = std::result::Result>; pub mod score; + +#[cfg(test)] +pub mod test_utils; + pub struct AdapterPool(sqlx::SqlitePool); pub struct AdapterBuilder { database_url: String, diff --git a/koucha/src/score.rs b/koucha/src/score.rs index 8b27b09..e289c6e 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -191,3 +191,199 @@ impl BoostedScore { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::get_datetime; + + #[test] + fn gravity_default() { + let gravity = Gravity::new(None); + assert_eq!(i64::from(gravity), default::GRAVITY); + } + + #[test] + fn boost_default() { + let boost = Boost::new(None); + assert_eq!(i64::from(boost), default::BOOST); + } + + // "Score" Tests + + #[test] + fn new() { + let score = TimedScore::new(); + assert_eq!(score.value, Score(default::INITIAL_SCORE)); + } + + #[test] + fn new_with_values() { + let dt = get_datetime(); + let score = TimedScore::new_with_initial_and_time(Score(10), dt); + assert_eq!(score.value, Score(10)); + assert_eq!(score.last_updated, dt); + } + + #[test] + fn update_score_stays_decaying() { + let dt = get_datetime(); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); + + score.update_score_at_time(gravity, dt2).get_decaying().unwrap(); + } + + #[test] + fn update_score_stays_frozen() { + let dt = get_datetime(); + let score = TimedScore::Boosted( + BoostedScore { value: Score(10), boosted_at: dt } + ); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + + score.update_score_at_time(gravity, dt2).get_boosted().unwrap(); + } + + #[test] + fn update_score_thaws_and_decays() { + let dt = get_datetime(); + let score = TimedScore::Boosted( + BoostedScore { value: Score(10), boosted_at: dt } + ); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds( + default::BOOST_FREEZE_IN_SECONDS + SECONDS_IN_A_DAY + ); + + let updated = score.update_score_at_time(gravity, dt2) + .get_decaying().unwrap(); + assert!(updated.value < Score(10)) + } + + #[test] + fn get_decaying_success() { + let dt = get_datetime(); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); + + score.get_decaying().unwrap(); + } + + #[test] + #[should_panic = "Attempted to get_boosted() of a decaying score"] + fn get_boosted_failure() { + let dt = get_datetime(); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); + + score.get_boosted().unwrap(); + } + + #[test] + #[should_panic = "Attempted to get_decaying() of a boosted score"] + fn get_decaying_failure() { + let dt = get_datetime(); + let boost = Boost::new(None); + let score = TimedScore::Boosted( + TimedScore::new_with_initial_and_time(Score(10), dt) + .boost_at_time(boost, dt) + ); + + score.get_decaying().unwrap(); + } + + #[test] + fn get_boosted_success() { + let dt = get_datetime(); + let boost = Boost::new(None); + let score = TimedScore::Boosted( + TimedScore::new_with_initial_and_time(Score(10), dt) + .boost_at_time(boost, dt) + ); + + score.get_boosted().unwrap(); + } + + // "DecayingScore" Tests + + #[test] + fn apply_gravity_to_future() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let future = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); + let gravity = Gravity::new(None); + + let updated = score.apply_gravity_to_time(gravity, future); + + assert!(updated.value < Score(10)); + assert_eq!(updated.last_updated, future); + } + + #[test] + fn apply_gravity_to_past() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let past = dt - TimeDelta::seconds(SECONDS_IN_A_DAY); + let gravity = Gravity::new(None); + + let updated = score.apply_gravity_to_time(gravity, past); + + assert!(updated.value > Score(10)); + assert_eq!(updated.last_updated, past); + } + + #[test] + fn boost() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let boost = Boost::new(None); + + let boosted = score.boost_at_time(boost, dt); + assert_eq!(boosted.value, Score(10) + Boost(default::BOOST)); + assert_eq!(boosted.boosted_at, dt); + } + + // "BoostedScore" tests + + #[test] + fn unboost() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let boost = Boost::new(None); + let boosted = score.boost_at_time(boost, dt); + + let unboosted = boosted.unboost(boost); + assert_eq!(unboosted.value, Score(10)); + assert_eq!(unboosted.last_updated, dt); + } + + #[test] + fn boosted_stays_frozen() { + let dt = get_datetime(); + let score = BoostedScore { value: Score(10), boosted_at: dt }; + + let last_second = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + + score.try_unfreeze_at_time(last_second).get_boosted().unwrap(); + } + + #[test] + fn boosted_thaws() { + let dt = get_datetime(); + let score = BoostedScore { value: Score(10), boosted_at: dt }; + + let first_second = dt + TimeDelta::days(default::BOOST_FREEZE_IN_SECONDS+1); + + score.try_unfreeze_at_time(first_second).get_decaying().unwrap(); + } +} diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs new file mode 100644 index 0000000..6492538 --- /dev/null +++ b/koucha/src/test_utils.rs @@ -0,0 +1,11 @@ +#![cfg(test)] + +use chrono::{ + Utc, + TimeZone, + DateTime +}; + +pub fn get_datetime() -> DateTime { + Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() +} From ce95a542278b7aeeb77bfe02a671ef43c2b876d4 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 13:10:21 -0800 Subject: [PATCH 28/32] Db, add core user functionality and tests; db mod Adds all the basic user functions, and tests for them. This is also intializes the DB Module, which will have more things in it --- koucha/src/db.rs | 11 +++ koucha/src/db/user.rs | 160 +++++++++++++++++++++++++++++++++++++++ koucha/src/lib.rs | 1 + koucha/src/test_utils.rs | 13 ++++ 4 files changed, 185 insertions(+) create mode 100644 koucha/src/db.rs create mode 100644 koucha/src/db/user.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs new file mode 100644 index 0000000..a19ee4a --- /dev/null +++ b/koucha/src/db.rs @@ -0,0 +1,11 @@ +mod user; +pub use user::User; + +macro_rules! define_key { + ($name:ident) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + }; +} + +define_key!(UserKey); diff --git a/koucha/src/db/user.rs b/koucha/src/db/user.rs new file mode 100644 index 0000000..f42491b --- /dev/null +++ b/koucha/src/db/user.rs @@ -0,0 +1,160 @@ +use crate::{ + Result, + AdapterPool, + db::UserKey, +}; + +pub struct UnparsedUser { + pub id: i64, + pub name: String, +} +impl UnparsedUser { + pub fn parse(self) -> Result { + Ok(User { + key: UserKey(self.id), + name: self.name + }) + } +} + +pub struct User { + key: UserKey, + name: String, +} + +impl User { + pub fn key(&self) -> UserKey { self.key } + pub fn name(&self) -> &str { &self.name } + + pub async fn get(pool: &AdapterPool, key: UserKey) -> Result { + sqlx::query_as!( + UnparsedUser, + "SELECT id, name FROM users WHERE id = ?", + key.0 + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn get_all(pool: &AdapterPool) -> Result> { + sqlx::query_as!( + UnparsedUser, + "SELECT id, name FROM users" + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedUser::parse).collect() + } + + pub async fn create(pool: &AdapterPool, name: &str) -> Result { + sqlx::query_as!( + UnparsedUser, + "INSERT INTO users (name) + VALUES (?) + RETURNING id, name", + name + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn update_name( + pool: &AdapterPool, key: UserKey, new_name: &str + ) -> Result<()> { + sqlx::query!( + "UPDATE users SET name = ? WHERE id = ?", + new_name, key.0 + ).execute(&pool.0).await?; + + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + test_utils::{ + USERNAME, USERNAME2, + setup_adapter, + }, + }; + + #[test] + fn parse() { + const UID: i64 = 1; + let unparsed_user = UnparsedUser { + id: UID, + name: USERNAME.to_string(), + }; + + let user = unparsed_user.parse().unwrap(); + assert_eq!(user.key.0, UID); + assert_eq!(user.name, USERNAME); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let new_user = User::create(pool, USERNAME).await.unwrap(); + + let fetched_user = User::get(pool, new_user.key).await.unwrap(); + assert_eq!(fetched_user.name, USERNAME); + assert_eq!(fetched_user.key.0, 1); + } + + #[tokio::test] + async fn get_all() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + User::create(pool, USERNAME).await.unwrap(); + User::create(pool, USERNAME2).await.unwrap(); + + let users = User::get_all(pool).await.unwrap(); + assert_eq!(users.len(), 2); + assert!(users.iter().any(|u| u.name == USERNAME)); + assert!(users.iter().any(|u| u.name == USERNAME2)); + } + + #[tokio::test] + async fn create_user() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, USERNAME).await.unwrap(); + + assert_eq!(user.name, USERNAME); + assert_eq!(user.key.0, 1); + } + + #[tokio::test] + async fn create_duplicate_user() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + User::create(pool, USERNAME).await.unwrap(); + let duplicate_user = User::create(pool, USERNAME).await; + + assert!(duplicate_user.is_err()); + } + + #[tokio::test] + async fn update_name() { + const NEW_USERNAME: &str = "Alicia"; + assert!(NEW_USERNAME != USERNAME); + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, USERNAME).await.unwrap(); + User::update_name(pool, user.key, NEW_USERNAME).await.unwrap(); + + let updated = User::get(pool, user.key).await.unwrap(); + assert_eq!(updated.name, NEW_USERNAME); + } + + #[tokio::test] + async fn update_name_to_duplicate() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user1 = User::create(pool, USERNAME).await.unwrap(); + User::create(pool, USERNAME2).await.unwrap(); + let status = User::update_name(pool, user1.key, USERNAME2).await; + + assert!(status.is_err()); + } +} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 3bf607b..5982237 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -2,6 +2,7 @@ use std::error::Error; type Result = std::result::Result>; +pub mod db; pub mod score; #[cfg(test)] diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index 6492538..7cd4601 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -1,11 +1,24 @@ #![cfg(test)] +use crate::{ + Adapter, + AdapterBuilder, +}; use chrono::{ Utc, TimeZone, DateTime }; +pub const USERNAME: &str = "Alice"; +pub const USERNAME2: &str = "Bob"; + pub fn get_datetime() -> DateTime { Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() } + +pub async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() +} From 09b26c1b396099125b2fd6aeac06efaa241a02e1 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 13:59:34 -0800 Subject: [PATCH 29/32] db, add channel and feed; user.get_feeds Adds the primary functionality for channel and feed Also adds a function to user to get the feeds associated with a user. --- koucha/Cargo.lock | 973 ++++++++++++++++++++++++++++++++++++++- koucha/Cargo.toml | 1 + koucha/src/db.rs | 6 + koucha/src/db/channel.rs | 179 +++++++ koucha/src/db/feed.rs | 191 ++++++++ koucha/src/db/user.rs | 44 +- koucha/src/test_utils.rs | 23 + 7 files changed, 1400 insertions(+), 17 deletions(-) create mode 100644 koucha/src/db/channel.rs create mode 100644 koucha/src/db/feed.rs diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index ff859af..4849805 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -26,12 +26,40 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "aws-lc-rs" +version = "1.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7b6141e96a8c160799cc2d5adecd5cbbe5054cb8c7c4af53da0f83bb7ad256" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c34dda4df7017c8db52132f0f8a2e0f8161649d15723ed63fc00c82d0f2081a" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] + [[package]] name = "base64" version = "0.22.1" @@ -87,15 +115,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.43" @@ -109,6 +151,25 @@ dependencies = [ "windows-link", ] +[[package]] +name = "cmake" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -124,6 +185,26 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -219,6 +300,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.15.0" @@ -228,6 +315,15 @@ dependencies = [ "serde", ] +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -283,6 +379,12 @@ dependencies = [ "spin", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.1.5" @@ -298,6 +400,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures-channel" version = "0.3.31" @@ -387,8 +495,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", ] [[package]] @@ -456,6 +599,108 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -592,12 +837,60 @@ dependencies = [ "hashbrown 0.16.1", ] +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "itoa" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + [[package]] name = "js-sys" version = "0.3.85" @@ -613,6 +906,7 @@ name = "koucha" version = "0.1.0" dependencies = [ "chrono", + "reqwest", "sqlx", "tokio", ] @@ -681,6 +975,12 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + [[package]] name = "md-5" version = "0.10.6" @@ -697,6 +997,12 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "mio" version = "1.1.1" @@ -719,7 +1025,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand", + "rand 0.8.5", "smallvec", "zeroize", ] @@ -760,6 +1066,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + [[package]] name = "parking" version = "2.2.1" @@ -870,6 +1182,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.18", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand 0.9.2", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.18", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + [[package]] name = "quote" version = "1.0.44" @@ -879,6 +1247,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rand" version = "0.8.5" @@ -886,8 +1260,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", ] [[package]] @@ -897,7 +1281,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", ] [[package]] @@ -906,7 +1300,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", ] [[package]] @@ -927,6 +1330,58 @@ dependencies = [ "bitflags", ] +[[package]] +name = "reqwest" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rsa" version = "0.9.10" @@ -940,13 +1395,94 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8", - "rand_core", + "rand_core 0.6.4", "signature", "spki", "subtle", "zeroize", ] +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "aws-lc-rs", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -959,12 +1495,53 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.228" @@ -1065,7 +1642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1152,7 +1729,7 @@ dependencies = [ "serde_json", "sha2", "smallvec", - "thiserror", + "thiserror 2.0.18", "tokio", "tokio-stream", "tracing", @@ -1226,7 +1803,7 @@ dependencies = [ "memchr", "once_cell", "percent-encoding", - "rand", + "rand 0.8.5", "rsa", "serde", "sha1", @@ -1234,7 +1811,7 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.18", "tracing", "whoami", ] @@ -1264,14 +1841,14 @@ dependencies = [ "md-5", "memchr", "once_cell", - "rand", + "rand 0.8.5", "serde", "serde_json", "sha2", "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.18", "tracing", "whoami", ] @@ -1295,7 +1872,7 @@ dependencies = [ "serde", "serde_urlencoded", "sqlx-core", - "thiserror", + "thiserror 2.0.18", "tracing", "url", ] @@ -1334,6 +1911,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + [[package]] name = "synstructure" version = "0.13.2" @@ -1345,13 +1931,54 @@ dependencies = [ "syn", ] +[[package]] +name = "system-configuration" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + [[package]] name = "thiserror" version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1418,6 +2045,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.18" @@ -1429,6 +2066,64 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.44" @@ -1461,6 +2156,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.19.0" @@ -1494,6 +2195,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.8" @@ -1524,12 +2231,40 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasite" version = "0.1.0" @@ -1549,6 +2284,20 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.108" @@ -1581,6 +2330,35 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.6.1" @@ -1591,6 +2369,15 @@ dependencies = [ "wasite", ] +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -1632,6 +2419,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + [[package]] name = "windows-result" version = "0.4.1" @@ -1650,6 +2448,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1659,6 +2466,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.60.2" @@ -1677,6 +2493,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -1692,6 +2523,22 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows-targets" version = "0.53.5" @@ -1702,103 +2549,199 @@ dependencies = [ "windows_aarch64_gnullvm 0.53.1", "windows_aarch64_msvc 0.53.1", "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm", + "windows_i686_gnullvm 0.53.1", "windows_i686_msvc 0.53.1", "windows_x86_64_gnu 0.53.1", "windows_x86_64_gnullvm 0.53.1", "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + [[package]] name = "windows_i686_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "windows_x86_64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + [[package]] name = "writeable" version = "0.6.2" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index 3da8f35..7a97cef 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] +reqwest = "0.13.1" tokio = { version = "1.49.0", features = ["full"] } sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.43" diff --git a/koucha/src/db.rs b/koucha/src/db.rs index a19ee4a..df11ecc 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -1,5 +1,9 @@ mod user; pub use user::User; +mod feed; +pub use feed::Feed; +mod channel; +pub use channel::Channel; macro_rules! define_key { ($name:ident) => { @@ -9,3 +13,5 @@ macro_rules! define_key { } define_key!(UserKey); +define_key!(FeedKey); +define_key!(ChannelKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs new file mode 100644 index 0000000..f8642f5 --- /dev/null +++ b/koucha/src/db/channel.rs @@ -0,0 +1,179 @@ +use reqwest::Url; +use chrono::{DateTime, Utc}; +use crate::{ + Result, + AdapterPool, + db::ChannelKey, +}; + +pub struct UnparsedChannel { + pub id: i64, + pub title: String, + pub link: String, + pub description: Option, + pub last_fetched: Option, +} +impl UnparsedChannel { + pub fn parse(self) -> Result { + Ok(Channel { + key: ChannelKey(self.id), + title: self.title, + link: Url::parse(&self.link)?, + description: self.description, + last_fetched: self.last_fetched.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), + }) + } +} + +pub struct Channel { + key: ChannelKey, + title: String, + link: Url, + description: Option, + last_fetched: Option>, +} + +impl Channel { + pub fn key(&self) -> ChannelKey { self.key } + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } + pub fn last_fetched(&self) -> Option> { self.last_fetched } + + pub async fn get_all(pool: &AdapterPool) -> Result> { + sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched FROM channels" + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedChannel::parse).collect() + } + + pub async fn get(pool: &AdapterPool, key: ChannelKey) -> Result { + sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched + FROM channels + WHERE id = ?", + key.0 + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn get_or_create( + pool: &AdapterPool, link: Url + ) -> Result { + let link_str = link.as_str(); + + sqlx::query_as!( + UnparsedChannel, + "INSERT INTO channels (title, link) + VALUES(?, ?) + ON CONFLICT(link) DO UPDATE SET link = link + RETURNING id, title, link, description, last_fetched", + link_str, link_str // We use the url as a placeholder title + ).fetch_one(&pool.0).await?.parse() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + test_utils::{ + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, + setup_adapter, + setup_channel, + }, + }; + use chrono::TimeZone; + + #[test] + fn parse_unparsed_item() { + const CHANNEL_ID: i64 = 1; + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + + let raw_channel = UnparsedChannel { + id: CHANNEL_ID, + title: CHANNEL_TITLE.to_string(), + link: FEED1.to_string(), + description: Some(CHANNEL_DESC.to_string()), + last_fetched: Some(date.to_rfc2822()), + }; + let channel = raw_channel.parse().unwrap(); + + assert_eq!(channel.key.0, CHANNEL_ID); + assert_eq!(channel.title, CHANNEL_TITLE); + assert_eq!(channel.link.as_str(), FEED1); + assert_eq!(channel.description, Some(CHANNEL_DESC.to_string())); + assert_eq!(channel.last_fetched, Some(date)); + } + + #[tokio::test] + async fn get_all() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url1 = Url::parse(FEED1).unwrap(); + let url2 = Url::parse(FEED2).unwrap(); + Channel::get_or_create(pool, url1).await.unwrap(); + Channel::get_or_create(pool, url2).await.unwrap(); + + let channels = Channel::get_all(pool).await.unwrap(); + assert_eq!(channels.len(), 2); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel_a = setup_channel(pool).await; + + let channel_b = Channel::get(pool, channel_a.key()).await.unwrap(); + + assert_eq!(channel_a.key, channel_b.key); + assert_eq!(channel_a.title, channel_b.title); + assert_eq!(channel_a.link, channel_b.link); + assert_eq!(channel_a.last_fetched, channel_b.last_fetched); + assert_eq!(channel_a.description, channel_b.description); + } + + #[tokio::test] + async fn create() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::get_or_create(pool, url_feed).await.unwrap(); + + assert!(channel.key().0 > 0); + assert_eq!(channel.link().as_str(), FEED1); + assert!(channel.title().len() > 0); + } + + #[tokio::test] + async fn create_duplicate_returns_existing() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed = Url::parse(FEED1).unwrap(); + + let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap(); + let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap(); + + assert_eq!(channel1.key(), channel2.key()); + } + + #[tokio::test] + async fn get_all_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed1 = Url::parse(FEED1).unwrap(); + let url_feed2 = Url::parse(FEED2).unwrap(); + + Channel::get_or_create(pool, url_feed1).await.unwrap(); + Channel::get_or_create(pool, url_feed2).await.unwrap(); + + let channels = Channel::get_all(pool).await.unwrap(); + + assert_eq!(channels.len(), 2); + } +} diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs new file mode 100644 index 0000000..da645e6 --- /dev/null +++ b/koucha/src/db/feed.rs @@ -0,0 +1,191 @@ +use crate::{ + AdapterPool, + Result, + db::{ + Channel, + ChannelKey, + FeedKey, + UserKey, + channel::UnparsedChannel, + }, +}; + +pub struct UnparsedFeed { + pub id: i64, + pub title: String, +} +impl UnparsedFeed { + pub fn parse(self) -> Result { + Ok(Feed { + key: FeedKey(self.id), + title: self.title, + }) + } +} + +pub struct Feed { + key: FeedKey, + title: String, +} + +impl Feed { + pub fn key(&self) -> FeedKey { self.key } + pub fn title(&self) -> &str { &self.title } + + pub async fn get( + pool: &AdapterPool, key: FeedKey + ) -> Result { + sqlx::query_as!( + UnparsedFeed, + "SELECT id, title FROM feeds WHERE id = ?", + key.0 + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn create( + pool: &AdapterPool, user_key: UserKey, title: &str + ) -> Result { + sqlx::query_as!( + UnparsedFeed, + "INSERT INTO feeds (user_id, title) + VALUES (?, ?) + RETURNING id as `id!`, title", + user_key.0, title + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn update_title( + pool: &AdapterPool, key: FeedKey, new_title: &str + ) -> Result<()> { + sqlx::query!( + "UPDATE feeds SET title = ? WHERE id = ?", + new_title, key.0 + ).execute(&pool.0).await?; + + Ok(()) + } + + pub async fn add_channel( + &self, pool: &AdapterPool, channel_key: ChannelKey + ) -> Result<()> { + sqlx::query!( + "INSERT INTO feed_channels (feed_id, channel_id) + VALUES (?, ?)", + self.key.0, channel_key.0 + ).execute(&pool.0).await?; + + Ok(()) + } + + pub async fn get_channels( + &self, pool: &AdapterPool + ) -> Result> { + sqlx::query_as!( + UnparsedChannel, + "SELECT c.id as `id!`, c.title, c.link, c.description, c.last_fetched + FROM channels c + JOIN feed_channels fc on c.id = fc.channel_id + WHERE fc.feed_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedChannel::parse).collect() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + db::User, + test_utils::{ + FEED_TITLE, USERNAME, FEED1, FEED2, + setup_adapter, + setup_feed, + setup_channel, + } + }; + use reqwest::Url; + + #[test] + fn parse() { + const FID: i64 = 1; + let uf = UnparsedFeed { + id: FID, + title: FEED_TITLE.to_string(), + }; + + let f = uf.parse().unwrap(); + + assert_eq!(f.key.0, FID); + assert_eq!(f.title, FEED_TITLE); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + + let gotten_feed = Feed::get(pool, feed.key).await.unwrap(); + + assert_eq!(feed.key, gotten_feed.key); + assert_eq!(feed.title, gotten_feed.title); + } + + #[tokio::test] + async fn create() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + let feed = Feed::create(pool, user.key(), FEED_TITLE).await.unwrap(); + + assert!(feed.key().0 > 0); + assert_eq!(feed.title(), FEED_TITLE); + } + + #[tokio::test] + async fn update_title() { + const NEW_FEED_TITLE: &str = "My NEW feed!"; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + + Feed::update_title(pool, feed.key(), NEW_FEED_TITLE).await.unwrap(); + + let updated = Feed::get(pool, feed.key()).await.unwrap(); + assert_eq!(updated.title(), NEW_FEED_TITLE); + } + + #[tokio::test] + async fn add_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + let channel = setup_channel(pool).await; + + feed.add_channel(pool, channel.key()).await.unwrap(); + + let channels = feed.get_channels(pool).await.unwrap(); + let gotten_channel = &channels[0]; + + assert_eq!(gotten_channel.key().0, channel.key().0); + } + + #[tokio::test] + async fn get_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + let url1 = Url::parse(FEED1).unwrap(); + let channel1 = Channel::get_or_create(pool, url1).await.unwrap(); + let url2 = Url::parse(FEED2).unwrap(); + let channel2 = Channel::get_or_create(pool, url2).await.unwrap(); + + feed.add_channel(pool, channel1.key()).await.unwrap(); + feed.add_channel(pool, channel2.key()).await.unwrap(); + + let channels = feed.get_channels(pool).await.unwrap(); + + assert_eq!(channels.len(), 2); + } +} diff --git a/koucha/src/db/user.rs b/koucha/src/db/user.rs index f42491b..038b82a 100644 --- a/koucha/src/db/user.rs +++ b/koucha/src/db/user.rs @@ -1,7 +1,11 @@ use crate::{ Result, AdapterPool, - db::UserKey, + db::{ + UserKey, + Feed, + feed::UnparsedFeed, + }, }; pub struct UnparsedUser { @@ -61,14 +65,26 @@ impl User { Ok(()) } + + pub async fn get_feeds(&self, pool: &AdapterPool) -> Result> { + let feeds: Result> = sqlx::query_as!( + UnparsedFeed, + "SELECT id, title FROM feeds WHERE user_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedFeed::parse).collect(); + + feeds + } } #[cfg(test)] mod tests { use super::*; use crate::{ + db::Feed, test_utils::{ - USERNAME, USERNAME2, + USERNAME, USERNAME2, FEED_TITLE, FEED_TITLE2, setup_adapter, }, }; @@ -157,4 +173,28 @@ mod tests { assert!(status.is_err()); } + + #[tokio::test] + async fn get_feeds() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + Feed::create(pool, user.key, FEED_TITLE).await.unwrap(); + Feed::create(pool, user.key, FEED_TITLE2).await.unwrap(); + + let feeds = user.get_feeds(pool).await.unwrap(); + assert_eq!(feeds.len(), 2); + assert!(feeds.iter().any(|f| f.title() == FEED_TITLE)); + assert!(feeds.iter().any(|f| f.title() == FEED_TITLE2)); + } + + #[tokio::test] + async fn get_feeds_empty() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + let feeds = user.get_feeds(pool).await.unwrap(); + + assert_eq!(feeds.len(), 0); + } } diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index 7cd4601..d02643c 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -3,15 +3,28 @@ use crate::{ Adapter, AdapterBuilder, + AdapterPool, + db::{ + Channel, + Feed, + User, + } }; +use reqwest::Url; use chrono::{ Utc, TimeZone, DateTime }; +pub const FEED1: &str = "https://example.com/feed"; +pub const FEED2: &str = "https://example2.com/feed"; pub const USERNAME: &str = "Alice"; pub const USERNAME2: &str = "Bob"; +pub const FEED_TITLE: &str = "My Feed!"; +pub const FEED_TITLE2: &str = "My Second Feed!"; +pub const CHANNEL_TITLE: &str = "My Channel!"; +pub const CHANNEL_DESC: &str = "My Channel's description"; pub fn get_datetime() -> DateTime { Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() @@ -22,3 +35,13 @@ pub async fn setup_adapter() -> Adapter { .database_url("sqlite::memory:") .create().await.unwrap() } + +pub async fn setup_channel(pool: &AdapterPool) -> Channel { + let url = Url::parse(FEED1).unwrap(); + Channel::get_or_create(pool, url).await.unwrap() +} + +pub async fn setup_feed(pool: &AdapterPool) -> Feed { + let user = User::create(pool, USERNAME).await.unwrap(); + Feed::create(pool, user.key(), FEED_TITLE).await.unwrap() +} From 55c3e967bce2c7b48b7a2105d384c4955254dfe1 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 6 Feb 2026 13:03:31 -0800 Subject: [PATCH 30/32] db, add item and functions to get items Creates item. It's pretty barebowns until I implement fetching. I also added get functions for feed and channel to get items with. --- koucha/src/db.rs | 3 + koucha/src/db/channel.rs | 33 ++++++++++- koucha/src/db/feed.rs | 18 ++++++ koucha/src/db/item.rs | 122 +++++++++++++++++++++++++++++++++++++++ koucha/src/test_utils.rs | 5 ++ 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 koucha/src/db/item.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs index df11ecc..4964fd9 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -4,6 +4,8 @@ mod feed; pub use feed::Feed; mod channel; pub use channel::Channel; +mod item; +pub use item::Item; macro_rules! define_key { ($name:ident) => { @@ -15,3 +17,4 @@ macro_rules! define_key { define_key!(UserKey); define_key!(FeedKey); define_key!(ChannelKey); +define_key!(ItemKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index f8642f5..0f38f3e 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -3,7 +3,11 @@ use chrono::{DateTime, Utc}; use crate::{ Result, AdapterPool, - db::ChannelKey, + db::{ + ChannelKey, + Item, + item::UnparsedItem, + }, }; pub struct UnparsedChannel { @@ -74,6 +78,17 @@ impl Channel { link_str, link_str // We use the url as a placeholder title ).fetch_one(&pool.0).await?.parse() } + + pub async fn get_items(&self, pool: &AdapterPool) -> Result> { + sqlx::query_as!( + UnparsedItem, + "SELECT id as `id!`, channel_id, fetched_at, title, description, + content + FROM items + WHERE channel_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect() + } } #[cfg(test)] @@ -81,7 +96,7 @@ mod tests { use super::*; use crate::{ test_utils::{ - FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, ITEM_GUID, ITEM_GUID2, setup_adapter, setup_channel, }, @@ -176,4 +191,18 @@ mod tests { assert_eq!(channels.len(), 2); } + + #[tokio::test] + async fn get_items() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + Item::get_or_create(pool, channel.key(), ITEM_GUID).await.unwrap(); + Item::get_or_create(pool, channel.key(), ITEM_GUID2).await.unwrap(); + + let items = channel.get_items(pool).await.unwrap(); + + assert_eq!(items.len(), 2); + } } diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index da645e6..a162190 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -5,8 +5,10 @@ use crate::{ Channel, ChannelKey, FeedKey, + Item, UserKey, channel::UnparsedChannel, + item::UnparsedItem, }, }; @@ -77,6 +79,22 @@ impl Feed { Ok(()) } + pub async fn get_items( + &self, pool: &AdapterPool, limit: u8, offset: u32 + ) -> Result> { + sqlx::query_as!( + UnparsedItem, + "SELECT i.id as `id!`, i.channel_id, i.fetched_at, i.title, i.description, + i.content + FROM items i + JOIN feed_items fi on i.id = fi.item_id + WHERE feed_id = ? AND archived = FALSE + ORDER BY score DESC + LIMIT ? OFFSET ?", + self.key.0, limit, offset + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect() + } + pub async fn get_channels( &self, pool: &AdapterPool ) -> Result> { diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs new file mode 100644 index 0000000..31ee857 --- /dev/null +++ b/koucha/src/db/item.rs @@ -0,0 +1,122 @@ +use crate::{ + Result, + AdapterPool, + db::{ + ChannelKey, + ItemKey, + }, +}; +use chrono::{DateTime, Utc}; + +pub struct UnparsedItem { + pub id: i64, + pub channel_id: i64, + pub fetched_at: Option, + + pub title: Option, + pub description: Option, + pub content: Option, +} + +impl UnparsedItem { + pub fn parse(self) -> Result { + Ok(Item { + key: ItemKey(self.id), + channel_id: ChannelKey(self.channel_id), + fetched_at: match self.fetched_at { + Some(dt_str) => Some(DateTime::parse_from_rfc2822(&dt_str)? + .with_timezone(&Utc)), + None => None, + }, + + title: self.title, + description: self.description, + content: self.content, + }) + } +} + +pub struct Item { + key: ItemKey, + channel_id: ChannelKey, + + fetched_at: Option>, + title: Option, + description: Option, + content: Option, +} + +impl Item { + pub fn key(&self) -> ItemKey { self.key } + pub fn channel(&self) -> ChannelKey { self.channel_id } + pub fn title(&self) -> Option<&str> { self.title.as_deref() } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } + pub fn content(&self) -> Option<&str> { self.content.as_deref() } + + pub async fn get_or_create( + pool: &AdapterPool, from_channel: ChannelKey, guid: &str + ) -> Result { + + let item = sqlx::query_as!( + UnparsedItem, + "INSERT INTO items (channel_id, guid) + VALUES (?, ?) + ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id + RETURNING id as `id!`, channel_id, fetched_at, title, description, + content", + from_channel.0, guid + ).fetch_one(&pool.0).await?.parse(); + + item + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::{ + ITEM_GUID, ITEM_TITLE, ITEM_DESC, ITEM_CONT, + setup_adapter, + setup_channel, + }; + use chrono::TimeZone; + + // UnparsedItem tests + #[test] + fn parse_unparsed_item() { + const ITEM_ID: i64 = 1; + const CHANNEL_ID: i64 = 1; + + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + let raw_item = UnparsedItem { + id: ITEM_ID, + channel_id: CHANNEL_ID, + fetched_at: Some(date.to_rfc2822()), + title: Some(ITEM_TITLE.to_string()), + description: Some(ITEM_DESC.to_string()), + content: Some(ITEM_CONT.to_string()), + }; + let item = raw_item.parse().unwrap(); + + assert_eq!(item.key.0, ITEM_ID); + assert_eq!(item.channel_id.0, CHANNEL_ID); + assert_eq!(item.fetched_at, Some(date)); + assert_eq!(item.title, Some(ITEM_TITLE.to_string())); + assert_eq!(item.description, Some(ITEM_DESC.to_string())); + assert_eq!(item.content, Some(ITEM_CONT.to_string())); + + } + + // Item Tests + #[tokio::test] + async fn get_or_create_duplicate() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let item1 = Item::get_or_create(pool, channel.key(), ITEM_GUID).await.unwrap(); + let item2 = Item::get_or_create(pool, channel.key(), ITEM_GUID).await.unwrap(); + + assert_eq!(item1.key(), item2.key()); + } +} diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index d02643c..6a21ca9 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -25,6 +25,11 @@ pub const FEED_TITLE: &str = "My Feed!"; pub const FEED_TITLE2: &str = "My Second Feed!"; pub const CHANNEL_TITLE: &str = "My Channel!"; pub const CHANNEL_DESC: &str = "My Channel's description"; +pub const ITEM_GUID: &str = "item-guid"; +pub const ITEM_GUID2: &str = "item-guid2"; +pub const ITEM_TITLE: &str = "My Item!"; +pub const ITEM_DESC: &str = "My Item's description"; +pub const ITEM_CONT: &str = "The content of my Item"; pub fn get_datetime() -> DateTime { Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() From 4467690ff19088f2c3b215623a3d34c2a2d6ec7a Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 6 Feb 2026 13:18:26 -0800 Subject: [PATCH 31/32] fetch, create fetch mod and AdapterClient Creates a fetch mod for fetching remote rss content. This implementation is barebones and not great since it doesn't pass any compression or timestamp information. --- koucha/Cargo.lock | 129 +++++++++++++++++++++++++++++++++++++ koucha/Cargo.toml | 1 + koucha/src/fetch.rs | 151 ++++++++++++++++++++++++++++++++++++++++++++ koucha/src/lib.rs | 8 ++- 4 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 koucha/src/fetch.rs diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index 4849805..c9fd8ab 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -26,6 +26,19 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atom_syndication" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f68d23e2cb4fd958c705b91a6b4c80ceeaf27a9e11651272a8389d5ce1a4a3" +dependencies = [ + "chrono", + "derive_builder", + "diligent-date-parser", + "never", + "quick-xml", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -260,6 +273,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "der" version = "0.7.10" @@ -271,6 +319,37 @@ dependencies = [ "zeroize", ] +[[package]] +name = "derive_builder" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" +dependencies = [ + "derive_builder_core", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -283,6 +362,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "diligent-date-parser" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ede7d79366f419921e2e2f67889c12125726692a313bffb474bd5f37a581e9" +dependencies = [ + "chrono", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -806,6 +894,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.1.0" @@ -907,6 +1001,7 @@ version = "0.1.0" dependencies = [ "chrono", "reqwest", + "rss", "sqlx", "tokio", ] @@ -1014,6 +1109,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "never" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" + [[package]] name = "num-bigint-dig" version = "0.8.6" @@ -1182,6 +1283,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.37.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +dependencies = [ + "encoding_rs", + "memchr", +] + [[package]] name = "quinn" version = "0.11.9" @@ -1402,6 +1513,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rss" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2107738f003660f0a91f56fd3e3bd3ab5d918b2ddaf1e1ec2136fb1c46f71bf" +dependencies = [ + "atom_syndication", + "derive_builder", + "never", + "quick-xml", +] + [[package]] name = "rustc-hash" version = "2.1.1" @@ -1894,6 +2017,12 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index 7a97cef..1106901 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] reqwest = "0.13.1" +rss = "2.0.12" tokio = { version = "1.49.0", features = ["full"] } sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.43" diff --git a/koucha/src/fetch.rs b/koucha/src/fetch.rs new file mode 100644 index 0000000..53ba2b9 --- /dev/null +++ b/koucha/src/fetch.rs @@ -0,0 +1,151 @@ +use crate::{ + Result, + db::Channel, + AdapterClient, +}; +use reqwest::Url; +use chrono::{DateTime, Utc}; +use std::hash::{Hash, Hasher}; + +pub struct FetchedRSSItem { + guid: String, + title: String, + description: String, + content: String, +} +impl FetchedRSSItem { + pub fn guid(&self) -> &str { &self.guid } + pub fn title(&self) -> &str { &self.title } + pub fn description(&self) -> &str { &self.description } + pub fn content(&self) -> &str { &self.content } + + fn parse(item: rss::Item) -> Self { + FetchedRSSItem { + guid: Self::get_or_create_guid(&item), + title: item.title().unwrap_or("").to_string(), + description: item.description().unwrap_or("").to_string(), + content: item.content().unwrap_or("").to_string(), + } + } + + fn get_or_create_guid(item: &rss::Item) -> String { + if let Some(guid) = item.guid() { + return guid.value().to_string(); + } + + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + item.link().unwrap_or("").hash(&mut hasher); + item.title().unwrap_or("").hash(&mut hasher); + item.description().unwrap_or("").hash(&mut hasher); + + format!("gen-{:x}", hasher.finish()) + } +} +pub struct FetchedRSSChannel { + title: String, + link: Url, + description: String, + + items: Vec, + + fetched_at: DateTime, +} +impl FetchedRSSChannel { + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> &str { &self.description } + pub fn items(&self) -> &[FetchedRSSItem] { &self.items } + pub fn fetched_at(&self) -> &DateTime { &self.fetched_at } + + pub async fn fetch_channel( + client: &AdapterClient, channel: Channel + ) -> Result> { + let bytestream = client.0.get(channel.link().clone()) + .send().await? + .bytes().await?; + + let rss_channel = rss::Channel::read_from(&bytestream[..])?; + + let now = Utc::now(); + + Ok(Some(FetchedRSSChannel::parse(rss_channel, now)?)) + } + + fn parse(rss: rss::Channel, fetched_at: DateTime) -> Result { + Ok(FetchedRSSChannel { + title: rss.title, + link: Url::parse(&rss.link)?, + description: rss.description, + + items: rss.items.into_iter().map(FetchedRSSItem::parse).collect(), + + fetched_at: fetched_at, + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::{ + ITEM_TITLE, ITEM_GUID, ITEM_GUID2, ITEM_DESC, ITEM_CONT, + CHANNEL_TITLE, CHANNEL_DESC, FEED1, + get_datetime + }; + + fn create_guid(value: String) -> rss::Guid { + rss::Guid { value, permalink: false } + } + + fn create_item(guid: rss::Guid) -> rss::Item { + rss::ItemBuilder::default() + .title(ITEM_TITLE.to_string()) + .guid(guid) + .description(ITEM_DESC.to_string()) + .content(ITEM_CONT.to_string()) + .build() + } + + fn create_channel(items: Vec) -> rss::Channel { + rss::ChannelBuilder::default() + .title(CHANNEL_TITLE.to_string()) + .description(CHANNEL_DESC.to_string()) + .link(FEED1.to_string()) + .items(items) + .build() + } + + #[test] + fn parse_item() { + let rss_guid = create_guid(ITEM_GUID.to_string()); + let rss_item = create_item(rss_guid); + let item = FetchedRSSItem::parse(rss_item); + + assert_eq!(item.guid, ITEM_GUID); + assert_eq!(item.title, ITEM_TITLE); + assert_eq!(item.description, ITEM_DESC); + assert_eq!(item.content, ITEM_CONT); + } + + #[test] + fn parse_feed() { + let rss_guid = create_guid(ITEM_GUID.to_string()); + let rss_guid2 = create_guid(ITEM_GUID2.to_string()); + let rss_item = create_item(rss_guid); + let rss_item2 = create_item(rss_guid2); + + let rss_channel = create_channel([rss_item, rss_item2].to_vec()); + + let date: DateTime = get_datetime(); + + let channel = FetchedRSSChannel::parse(rss_channel, date).unwrap(); + + assert_eq!(channel.title, CHANNEL_TITLE); + assert_eq!(channel.link.as_str(), FEED1); + assert_eq!(channel.description, CHANNEL_DESC); + assert_eq!(channel.fetched_at, date); + assert_eq!(channel.items.len(), 2); + assert!(channel.items.iter().any(|i| i.guid() == ITEM_GUID)); + assert!(channel.items.iter().any(|i| i.guid() == ITEM_GUID2)); + } +} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 5982237..a20a9dc 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,12 +3,15 @@ use std::error::Error; type Result = std::result::Result>; pub mod db; +pub mod fetch; pub mod score; #[cfg(test)] pub mod test_utils; pub struct AdapterPool(sqlx::SqlitePool); +pub struct AdapterClient(reqwest::Client); + pub struct AdapterBuilder { database_url: String, } @@ -29,15 +32,18 @@ impl AdapterBuilder { let db = sqlx::sqlite::SqlitePoolOptions::new() .connect(&self.database_url).await?; sqlx::migrate!().run(&db).await?; + let client = reqwest::Client::new(); - Ok(Adapter { db: AdapterPool(db) }) + Ok(Adapter { db: AdapterPool(db), client: AdapterClient(client) }) } } pub struct Adapter { db: AdapterPool, + client: AdapterClient, } impl Adapter { pub fn get_pool(&self) -> &AdapterPool { &self.db } + pub fn get_client(&self) -> &AdapterClient { &self.client } } From ecbb4f3bb6fb62ec00d4e01237143d21fdfeb636 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 6 Feb 2026 14:49:13 -0800 Subject: [PATCH 32/32] db&score, feed_channel impl & score from db Adds a feed_channel implementation which reflects a feed's specific settings per channel. Also added an UnparsedTimedScore to score which allows parsing to score from db in a controlled fashion. --- koucha/src/db.rs | 10 ++ koucha/src/db/channel.rs | 37 ++++++- koucha/src/db/feed_channel.rs | 188 ++++++++++++++++++++++++++++++++++ koucha/src/score.rs | 58 +++++++++++ 4 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 koucha/src/db/feed_channel.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs index 4964fd9..9be8130 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -2,6 +2,8 @@ mod user; pub use user::User; mod feed; pub use feed::Feed; +mod feed_channel; +pub use feed_channel::FeedChannel; mod channel; pub use channel::Channel; mod item; @@ -12,9 +14,17 @@ macro_rules! define_key { #[derive(PartialEq, Debug, Copy, Clone)] pub struct $name(i64); }; + + ($name:ident, $($field:ident : $type:ty),* $(,)?) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name { + $($field: $type),* + } + }; } define_key!(UserKey); define_key!(FeedKey); +define_key!(FeedChannelKey, feed_key: FeedKey, channel_key: ChannelKey); define_key!(ChannelKey); define_key!(ItemKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 0f38f3e..eaa03be 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -6,6 +6,8 @@ use crate::{ db::{ ChannelKey, Item, + FeedChannel, + feed_channel::UnparsedFeedChannel, item::UnparsedItem, }, }; @@ -79,6 +81,19 @@ impl Channel { ).fetch_one(&pool.0).await?.parse() } + async fn get_feed_channels( + &self, pool: &AdapterPool + ) -> Result> { + sqlx::query_as!( + UnparsedFeedChannel, + "SELECT channel_id, feed_id, initial_score, gravity, boost + FROM feed_channels + WHERE channel_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedFeedChannel::parse).collect() + } + pub async fn get_items(&self, pool: &AdapterPool) -> Result> { sqlx::query_as!( UnparsedItem, @@ -95,8 +110,10 @@ impl Channel { mod tests { use super::*; use crate::{ + db::{Feed, User}, test_utils::{ - FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, ITEM_GUID, ITEM_GUID2, + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, USERNAME, FEED_TITLE, + FEED_TITLE2, ITEM_GUID, ITEM_GUID2, setup_adapter, setup_channel, }, @@ -192,6 +209,24 @@ mod tests { assert_eq!(channels.len(), 2); } + #[tokio::test] + async fn get_feed_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let user = User::create(pool, USERNAME).await.unwrap(); + let feed1 = Feed::create(pool, user.key(), FEED_TITLE).await.unwrap(); + let feed2 = Feed::create(pool, user.key(), FEED_TITLE2).await.unwrap(); + + feed1.add_channel(pool, channel.key).await.unwrap(); + feed2.add_channel(pool, channel.key).await.unwrap(); + + let fc_list = channel.get_feed_channels(pool).await.unwrap(); + + assert_eq!(fc_list.len(), 2); + } + #[tokio::test] async fn get_items() { let adapter = setup_adapter().await; diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs new file mode 100644 index 0000000..e2df61a --- /dev/null +++ b/koucha/src/db/feed_channel.rs @@ -0,0 +1,188 @@ +use crate::{ + Result, + AdapterPool, + db::{ + Channel, + ChannelKey, + Feed, + FeedKey, + FeedChannelKey, + Item, + }, + score::{ + Score, + Gravity, + Boost, + }, +}; +use chrono::{Utc, DateTime}; + +pub struct UnparsedFeedChannel { + pub channel_id: i64, + pub feed_id: i64, + pub initial_score: Option, + pub gravity: Option, + pub boost: Option, +} +impl UnparsedFeedChannel { + pub fn parse(self) -> Result { + Ok(FeedChannel { + key: FeedChannelKey { + feed_key: FeedKey(self.feed_id), + channel_key: ChannelKey(self.channel_id), + }, + initial_score: Score::new(self.initial_score), + gravity: Gravity::new(self.gravity), + boost: Boost::new(self.boost), + }) + } +} + +pub struct FeedChannel { + key: FeedChannelKey, + initial_score: Score, + gravity: Gravity, + boost: Boost, +} + +impl FeedChannel { + pub async fn get_channel(&self, pool: &AdapterPool) -> Result { + Channel::get(pool, self.key.channel_key).await + } + pub async fn get_feed(&self, pool: &AdapterPool) -> Result { + Feed::get(pool, self.key.feed_key).await + } + + pub async fn add_item( + &self, pool: &AdapterPool, item: &Item + ) -> Result<()> { + self.add_item_at(pool, item, Utc::now()).await + } + + async fn add_item_at( + &self, pool: &AdapterPool, item: &Item, add_at: DateTime + ) -> Result<()> { + let int_item_id = item.key().0; + let int_initial_score = i64::from(self.initial_score); + let string_last_updated = add_at.to_rfc2822(); + + sqlx::query!( + "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated) + VALUES (?, ?, ?, ?)", + self.key.feed_key.0, int_item_id, int_initial_score, string_last_updated + ).execute(&pool.0).await?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use reqwest::Url; + use crate::{ + db::{ + Channel, + FeedKey, + User + }, + test_utils::{ + FEED1, setup_adapter, get_datetime + }, + }; + + #[test] + fn parse() { + const CID: i64 = 1; + const FID: i64 = 2; + const IS: i64 = 3; + const G: i64 = 4; + const B: i64 = 5; + let ufc = UnparsedFeedChannel { + channel_id: CID, + feed_id: FID, + initial_score: Some(IS), + gravity: Some(G), + boost: Some(B), + }; + + let fc = ufc.parse().unwrap(); + + assert_eq!(fc.key.channel_key.0, CID); + assert_eq!(fc.key.feed_key.0, FID); + assert_eq!(i64::from(fc.initial_score), IS); + assert_eq!(i64::from(fc.gravity), G); + assert_eq!(i64::from(fc.boost), B); + } + + // FeedChannel Tests + #[tokio::test] + async fn get_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let url = Url::parse(FEED1).unwrap(); + let channel = Channel::get_or_create(pool, url).await.unwrap(); + + let fc = FeedChannel { + key: FeedChannelKey { + feed_key: FeedKey(1), // Fake Feed + channel_key: channel.key(), + }, + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), + }; + + let channel_from_fc = fc.get_channel(pool).await.unwrap(); + assert_eq!(channel_from_fc.key(), channel.key()); + } + + #[tokio::test] + async fn get_feed() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.key(), "My Feed").await.unwrap(); + + let fc = FeedChannel { + key: FeedChannelKey { + feed_key: feed.key(), + channel_key: ChannelKey(1), // Fake Channel + }, + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), + }; + + let feed_from_fc = fc.get_feed(pool).await.unwrap(); + assert_eq!(feed_from_fc.key(), feed.key()); + } + + #[tokio::test] + pub async fn add_item() { + let dt = get_datetime(); + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.key(), "My Feed").await.unwrap(); + let url = Url::parse(FEED1).unwrap(); + let channel = Channel::get_or_create(pool, url).await.unwrap(); + let fc = FeedChannel { + key: FeedChannelKey { + feed_key: feed.key(), + channel_key: channel.key(), + }, + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), + }; + + let item = Item::get_or_create(pool, channel.key(), "item-guid").await.unwrap(); + fc.add_item_at(pool, &item, dt).await.unwrap(); + + let items = feed.get_items(pool, 1, 0).await.unwrap(); + assert_eq!(items[0].key(), item.key()); + } +} diff --git a/koucha/src/score.rs b/koucha/src/score.rs index e289c6e..754ca17 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -61,6 +61,41 @@ impl Gravity { ) } } +pub struct UnparsedTimedScore { + pub value: i64, + pub last_updated: DateTime, + pub last_boosted: Option>, +} + +impl UnparsedTimedScore { + pub fn parse(self) -> TimedScore { + match self.last_boosted { + None => TimedScore::Decaying(DecayingScore { + value: Score(self.value), + last_updated: self.last_updated, + }), + Some(last_boosted) => TimedScore::Boosted(BoostedScore { + value: Score(self.value), + boosted_at: last_boosted, + }), + } + } + + pub fn unparse(ts: TimedScore) -> Self { + match ts { + TimedScore::Decaying(ds) => UnparsedTimedScore { + value: ds.value.into(), + last_updated: ds.last_updated, + last_boosted: None, + }, + TimedScore::Boosted(bs) => UnparsedTimedScore { + value: bs.value.into(), + last_updated: bs.boosted_at, + last_boosted: Some(bs.boosted_at), + }, + } + } +} #[derive(Clone)] pub enum TimedScore { @@ -211,6 +246,29 @@ mod tests { // "Score" Tests + #[test] + fn parse_decaying() { + let ups = UnparsedTimedScore { + value: 10, + last_updated: get_datetime(), + last_boosted: None, + }; + + ups.parse().get_decaying().unwrap(); + } + + #[test] + fn parse_boosted() { + let dt = get_datetime(); + let ups = UnparsedTimedScore { + value: 10, + last_updated: dt, + last_boosted: Some(dt), + }; + + ups.parse().get_boosted().unwrap(); + } + #[test] fn new() { let score = TimedScore::new();