@@ -49,7 +49,7 @@ pub trait PreprocCache {
49
49
async fn set ( & mut self , key : & CacheKey , value : Vec < u8 > ) -> Result < ( ) > ;
50
50
}
51
51
52
- async fn pragmas ( db : & Connection ) -> Result < ( ) > {
52
+ async fn connect_pragmas ( db : & Connection ) -> Result < ( ) > {
53
53
// https://phiresky.github.io/blog/2020/sqlite-performance-tuning/
54
54
//let want_page_size = 32768;
55
55
//db.execute(&format!("pragma page_size = {};", want_page_size))
@@ -63,9 +63,6 @@ async fn pragmas(db: &Connection) -> Result<()> {
63
63
pragma synchronous = off; -- integrity isn't very important here
64
64
pragma mmap_size = 30000000000;
65
65
66
- pragma application_id = 924716026;
67
- pragma user_version = 2; -- todo: on upgrade clear db if version is unexpected
68
-
69
66
create table if not exists preproc_cache (
70
67
adapter text not null,
71
68
adapter_version integer not null,
@@ -80,23 +77,36 @@ async fn pragmas(db: &Connection) -> Result<()> {
80
77
" ,
81
78
)
82
79
} )
83
- . await ?;
84
- /* let jm: String = db
85
- .call(|db| db.pragma_query_value(None, "journal_mode ", |r| r.get(0))? )
80
+ . await . context ( "connect_pragmas" ) ?;
81
+ let jm: i64 = db
82
+ . call ( |db| db. pragma_query_value ( None , "application_id " , |r| r. get ( 0 ) ) )
86
83
. await ?;
87
- if &jm != "wal" {
88
- anyhow::bail!("journal mode is not wal");
89
- }*/
84
+ if jm != 924716026 {
85
+ // (probably) newly created db
86
+ create_pragmas ( db) . await . context ( "create_pragmas" ) ?;
87
+ }
90
88
Ok ( ( ) )
91
89
}
92
90
91
+ async fn create_pragmas ( db : & Connection ) -> Result < ( ) > {
92
+ db. call ( |db| {
93
+ db. execute_batch (
94
+ "
95
+ pragma application_id = 924716026;
96
+ pragma user_version = 2; -- todo: on upgrade clear db if version is unexpected
97
+ " ,
98
+ )
99
+ } )
100
+ . await ?;
101
+ Ok ( ( ) )
102
+ }
93
103
struct SqliteCache {
94
104
db : Connection ,
95
105
}
96
106
impl SqliteCache {
97
107
async fn new ( path : & Path ) -> Result < SqliteCache > {
98
108
let db = Connection :: open ( path. join ( "cache.sqlite3" ) ) . await ?;
99
- pragmas ( & db) . await ?;
109
+ connect_pragmas ( & db) . await ?;
100
110
101
111
Ok ( SqliteCache { db } )
102
112
}
0 commit comments