@@ -2,7 +2,7 @@ use axum::{ routing::get, extract::{ State, Path }, http::StatusCode, response::
2
2
use libsql:: { Builder , Database } ;
3
3
use std:: sync:: { Arc } ;
4
4
use std:: vec:: { Vec } ;
5
- use tokio:: sync:: { Mutex } ;
5
+ use tokio:: sync:: { RwLock } ;
6
6
7
7
#[ shuttle_runtime:: main]
8
8
async fn main (
@@ -30,7 +30,7 @@ async fn main(
30
30
31
31
// Add local db to shared state
32
32
let app_state = Arc :: new ( AppState {
33
- db : Arc :: new ( Mutex :: new ( db) ) ,
33
+ db : Arc :: new ( RwLock :: new ( db) ) ,
34
34
remote_url : db_url,
35
35
auth : auth,
36
36
sync_auth : sync_auth
@@ -52,7 +52,7 @@ async fn main(
52
52
53
53
#[ derive( Clone ) ]
54
54
struct AppState {
55
- db : Arc < Mutex < Database > > ,
55
+ db : Arc < RwLock < Database > > ,
56
56
remote_url : String ,
57
57
auth : String ,
58
58
sync_auth : String
@@ -81,7 +81,7 @@ struct ModListEntry {
81
81
async fn mod_list (
82
82
State ( state) : State < Arc < AppState > >
83
83
) -> Result < Json < Vec < ModListEntry > > , StatusCode > {
84
- let connection = match state. db . lock ( ) . await . connect ( ) {
84
+ let connection = match state. db . read ( ) . await . connect ( ) {
85
85
Ok ( val) => val,
86
86
Err ( _err) => {
87
87
println ! ( "Connection failed" ) ;
@@ -141,7 +141,7 @@ async fn mod_data(
141
141
State ( state) : State < Arc < AppState > > ,
142
142
Path ( mod_name) : Path < String >
143
143
) -> Result < Json < ModEntry > , StatusCode > {
144
- let connection = match state. db . lock ( ) . await . connect ( ) {
144
+ let connection = match state. db . read ( ) . await . connect ( ) {
145
145
Ok ( val) => val,
146
146
Err ( _err) => {
147
147
println ! ( "Connection failed" ) ;
@@ -208,7 +208,7 @@ async fn sync_local(
208
208
return Redirect :: to ( "/api" ) ;
209
209
}
210
210
211
- let conn = state. db . lock ( ) . await . connect ( ) . expect ( "Loacl connection failed" ) ;
211
+ let conn = state. db . read ( ) . await . connect ( ) . expect ( "Local connection failed" ) ;
212
212
213
213
println ! ( "Dropping old tables" ) ;
214
214
conn. execute ( "DROP TABLE info" , ( ) ) . await . expect ( "Drop 'info' failed" ) ;
0 commit comments