diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-03 08:54:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-03 08:54:00 +0000 |
| commit | 2f8ecd482077d82f2d1a937c7f979eaaa87a27b2 (patch) | |
| tree | cd892cde6ef6fd7ff654377946cab5b95339276f /src/git/handlers.rs | |
| parent | 62a3855cb96616caf704a0f112fb2ade99fb8b45 (diff) | |
feat: implement LMDB database backend
- Add nostr-lmdb dependency (v0.44) for persistent storage
- Create SharedDatabase type alias for database abstraction
- Update all database-related functions to use trait object
- Support runtime selection via NGIT_DATABASE_BACKEND env var
Database backends:
- memory: In-memory (default, fastest, no persistence)
- lmdb: LMDB backend (persistent, general purpose)
All 34 tests pass with the new implementation.
Diffstat (limited to 'src/git/handlers.rs')
| -rw-r--r-- | src/git/handlers.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/git/handlers.rs b/src/git/handlers.rs index e84cabb..8e5f5e1 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs | |||
| @@ -4,9 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use http_body_util::Full; | 5 | use http_body_util::Full; |
| 6 | use hyper::{body::Bytes, Response, StatusCode}; | 6 | use hyper::{body::Bytes, Response, StatusCode}; |
| 7 | use nostr_relay_builder::prelude::MemoryDatabase; | ||
| 8 | use std::path::PathBuf; | 7 | use std::path::PathBuf; |
| 9 | use std::sync::Arc; | ||
| 10 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; | 8 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; |
| 11 | use tracing::{debug, error, info, warn}; | 9 | use tracing::{debug, error, info, warn}; |
| 12 | 10 | ||
| @@ -18,6 +16,7 @@ use super::protocol::{GitService, PktLine}; | |||
| 18 | use super::subprocess::GitSubprocess; | 16 | use super::subprocess::GitSubprocess; |
| 19 | use super::try_set_head_if_available; | 17 | use super::try_set_head_if_available; |
| 20 | 18 | ||
| 19 | use crate::nostr::builder::SharedDatabase; | ||
| 21 | use crate::nostr::events::RepositoryState; | 20 | use crate::nostr::events::RepositoryState; |
| 22 | 21 | ||
| 23 | /// Handle GET /info/refs?service=git-{upload,receive}-pack | 22 | /// Handle GET /info/refs?service=git-{upload,receive}-pack |
| @@ -178,7 +177,7 @@ pub async fn handle_upload_pack( | |||
| 178 | pub async fn handle_receive_pack( | 177 | pub async fn handle_receive_pack( |
| 179 | repo_path: PathBuf, | 178 | repo_path: PathBuf, |
| 180 | request_body: Bytes, | 179 | request_body: Bytes, |
| 181 | database: Option<Arc<MemoryDatabase>>, | 180 | database: Option<SharedDatabase>, |
| 182 | identifier: &str, | 181 | identifier: &str, |
| 183 | owner_pubkey: &str, | 182 | owner_pubkey: &str, |
| 184 | ) -> Result<Response<Full<Bytes>>, GitError> { | 183 | ) -> Result<Response<Full<Bytes>>, GitError> { |
| @@ -310,7 +309,7 @@ pub async fn handle_receive_pack( | |||
| 310 | /// 5. Validates that pushed refs match the state | 309 | /// 5. Validates that pushed refs match the state |
| 311 | /// 6. Validates refs/nostr/<event-id> has valid event id and if event exists, `c` tag matches ref | 310 | /// 6. Validates refs/nostr/<event-id> has valid event id and if event exists, `c` tag matches ref |
| 312 | async fn authorize_push( | 311 | async fn authorize_push( |
| 313 | database: &Arc<MemoryDatabase>, | 312 | database: &SharedDatabase, |
| 314 | identifier: &str, | 313 | identifier: &str, |
| 315 | owner_pubkey: &str, | 314 | owner_pubkey: &str, |
| 316 | request_body: &Bytes, | 315 | request_body: &Bytes, |