@@ -30,7 +30,7 @@ use crate::stitching::ForwardPartialPathStitcher;
30
30
use crate :: CancellationError ;
31
31
use crate :: CancellationFlag ;
32
32
33
- const VERSION : usize = 2 ;
33
+ const VERSION : usize = 3 ;
34
34
35
35
const SCHEMA : & str = r#"
36
36
CREATE TABLE metadata (
@@ -40,18 +40,18 @@ const SCHEMA: &str = r#"
40
40
file TEXT PRIMARY KEY,
41
41
tag TEXT NOT NULL,
42
42
error TEXT,
43
- json BLOB NOT NULL
43
+ value BLOB NOT NULL
44
44
) STRICT;
45
45
CREATE TABLE file_paths (
46
46
file TEXT NOT NULL,
47
47
local_id INTEGER NOT NULL,
48
- json BLOB NOT NULL,
48
+ value BLOB NOT NULL,
49
49
FOREIGN KEY(file) REFERENCES graphs(file)
50
50
) STRICT;
51
51
CREATE TABLE root_paths (
52
52
file TEXT NOT NULL,
53
53
symbol_stack TEXT NOT NULL,
54
- json BLOB NOT NULL,
54
+ value BLOB NOT NULL,
55
55
FOREIGN KEY(file) REFERENCES graphs(file)
56
56
) STRICT;
57
57
"# ;
@@ -75,7 +75,9 @@ pub enum StorageError {
75
75
#[ error( transparent) ]
76
76
Serde ( #[ from] serde:: Error ) ,
77
77
#[ error( transparent) ]
78
- SerdeJson ( #[ from] serde_json:: Error ) ,
78
+ RmpSerdeDecode ( #[ from] rmp_serde:: decode:: Error ) ,
79
+ #[ error( transparent) ]
80
+ RmpSerdeEncode ( #[ from] rmp_serde:: encode:: Error ) ,
79
81
}
80
82
81
83
pub type Result < T > = std:: result:: Result < T , StorageError > ;
@@ -274,14 +276,14 @@ impl SQLiteWriter {
274
276
error : & str ,
275
277
) -> Result < ( ) > {
276
278
copious_debugging ! ( "--> Store error for {}" , file. display( ) ) ;
277
- let mut stmt =
278
- conn . prepare_cached ( "INSERT INTO graphs (file, tag, error, json ) VALUES (?, ?, ?, ?)" ) ?;
279
+ let mut stmt = conn
280
+ . prepare_cached ( "INSERT INTO graphs (file, tag, error, value ) VALUES (?, ?, ?, ?)" ) ?;
279
281
let graph = crate :: serde:: StackGraph :: default ( ) ;
280
282
stmt. execute ( (
281
283
& file. to_string_lossy ( ) ,
282
284
tag,
283
285
error,
284
- & serde_json :: to_vec ( & graph) ?,
286
+ & rmp_serde :: to_vec ( & graph) ?,
285
287
) ) ?;
286
288
Ok ( ( ) )
287
289
}
@@ -319,9 +321,9 @@ impl SQLiteWriter {
319
321
let file_str = graph[ file] . name ( ) ;
320
322
copious_debugging ! ( "--> Store graph for {}" , file_str) ;
321
323
let mut stmt =
322
- conn. prepare_cached ( "INSERT INTO graphs (file, tag, json ) VALUES (?, ?, ?)" ) ?;
324
+ conn. prepare_cached ( "INSERT INTO graphs (file, tag, value ) VALUES (?, ?, ?)" ) ?;
323
325
let graph = serde:: StackGraph :: from_graph_filter ( graph, & FileFilter ( file) ) ;
324
- stmt. execute ( ( file_str, tag, & serde_json :: to_vec ( & graph) ?) ) ?;
326
+ stmt. execute ( ( file_str, tag, & rmp_serde :: to_vec ( & graph) ?) ) ?;
325
327
Ok ( ( ) )
326
328
}
327
329
@@ -340,9 +342,10 @@ impl SQLiteWriter {
340
342
{
341
343
let file_str = graph[ file] . name ( ) ;
342
344
let mut node_stmt =
343
- conn. prepare_cached ( "INSERT INTO file_paths (file, local_id, json) VALUES (?, ?, ?)" ) ?;
344
- let mut root_stmt = conn
345
- . prepare_cached ( "INSERT INTO root_paths (file, symbol_stack, json) VALUES (?, ?, ?)" ) ?;
345
+ conn. prepare_cached ( "INSERT INTO file_paths (file, local_id, value) VALUES (?, ?, ?)" ) ?;
346
+ let mut root_stmt = conn. prepare_cached (
347
+ "INSERT INTO root_paths (file, symbol_stack, value) VALUES (?, ?, ?)" ,
348
+ ) ?;
346
349
#[ cfg_attr( not( feature = "copious-debugging" ) , allow( unused) ) ]
347
350
let mut node_path_count = 0usize ;
348
351
#[ cfg_attr( not( feature = "copious-debugging" ) , allow( unused) ) ]
@@ -361,7 +364,7 @@ impl SQLiteWriter {
361
364
) ;
362
365
let symbol_stack = path. symbol_stack_precondition . storage_key ( graph, partials) ;
363
366
let path = serde:: PartialPath :: from_partial_path ( graph, partials, path) ;
364
- root_stmt. execute ( ( file_str, symbol_stack, & serde_json :: to_vec ( & path) ?) ) ?;
367
+ root_stmt. execute ( ( file_str, symbol_stack, & rmp_serde :: to_vec ( & path) ?) ) ?;
365
368
root_path_count += 1 ;
366
369
} else if start_node. is_in_file ( file) {
367
370
copious_debugging ! (
@@ -372,7 +375,7 @@ impl SQLiteWriter {
372
375
node_stmt. execute ( (
373
376
file_str,
374
377
path. start_node . local_id ,
375
- & serde_json :: to_vec ( & path) ?,
378
+ & rmp_serde :: to_vec ( & path) ?,
376
379
) ) ?;
377
380
node_path_count += 1 ;
378
381
} else {
@@ -499,8 +502,8 @@ impl SQLiteReader {
499
502
}
500
503
copious_debugging ! ( " * Load from database" ) ;
501
504
let mut stmt = conn. prepare_cached ( "SELECT json FROM graphs WHERE file = ?" ) ?;
502
- let json_graph = stmt. query_row ( [ file] , |row| row. get :: < _ , Vec < u8 > > ( 0 ) ) ?;
503
- let file_graph = serde_json :: from_slice :: < serde:: StackGraph > ( & json_graph ) ?;
505
+ let value = stmt. query_row ( [ file] , |row| row. get :: < _ , Vec < u8 > > ( 0 ) ) ?;
506
+ let file_graph = rmp_serde :: from_slice :: < serde:: StackGraph > ( & value ) ?;
504
507
file_graph. load_into ( graph) ?;
505
508
Ok ( ( ) )
506
509
}
@@ -539,24 +542,24 @@ impl SQLiteReader {
539
542
let file = self . graph [ file] . name ( ) ;
540
543
let mut stmt = self
541
544
. conn
542
- . prepare_cached ( "SELECT file,json from file_paths WHERE file = ? AND local_id = ?" ) ?;
545
+ . prepare_cached ( "SELECT file,value from file_paths WHERE file = ? AND local_id = ?" ) ?;
543
546
let paths = stmt. query_map ( ( file, id. local_id ( ) ) , |row| {
544
547
let file = row. get :: < _ , String > ( 0 ) ?;
545
- let json = row. get :: < _ , Vec < u8 > > ( 1 ) ?;
546
- Ok ( ( file, json ) )
548
+ let value = row. get :: < _ , Vec < u8 > > ( 1 ) ?;
549
+ Ok ( ( file, value ) )
547
550
} ) ?;
548
551
#[ cfg_attr( not( feature = "copious-debugging" ) , allow( unused) ) ]
549
552
let mut count = 0usize ;
550
553
for path in paths {
551
554
cancellation_flag. check ( "loading node paths" ) ?;
552
- let ( file, json ) = path?;
555
+ let ( file, value ) = path?;
553
556
Self :: load_graph_for_file_inner (
554
557
& file,
555
558
& mut self . graph ,
556
559
& mut self . loaded_graphs ,
557
560
& self . conn ,
558
561
) ?;
559
- let path = serde_json :: from_slice :: < serde:: PartialPath > ( & json ) ?;
562
+ let path = rmp_serde :: from_slice :: < serde:: PartialPath > ( & value ) ?;
560
563
let path = path. to_partial_path ( & mut self . graph , & mut self . partials ) ?;
561
564
copious_debugging ! (
562
565
" > Loaded {}" ,
@@ -593,24 +596,24 @@ impl SQLiteReader {
593
596
}
594
597
let mut stmt = self
595
598
. conn
596
- . prepare_cached ( "SELECT file,json from root_paths WHERE symbol_stack = ?" ) ?;
599
+ . prepare_cached ( "SELECT file,value from root_paths WHERE symbol_stack = ?" ) ?;
597
600
let paths = stmt. query_map ( [ symbol_stack] , |row| {
598
601
let file = row. get :: < _ , String > ( 0 ) ?;
599
- let json = row. get :: < _ , Vec < u8 > > ( 1 ) ?;
600
- Ok ( ( file, json ) )
602
+ let value = row. get :: < _ , Vec < u8 > > ( 1 ) ?;
603
+ Ok ( ( file, value ) )
601
604
} ) ?;
602
605
#[ cfg_attr( not( feature = "copious-debugging" ) , allow( unused) ) ]
603
606
let mut count = 0usize ;
604
607
for path in paths {
605
608
cancellation_flag. check ( "loading root paths" ) ?;
606
- let ( file, json ) = path?;
609
+ let ( file, value ) = path?;
607
610
Self :: load_graph_for_file_inner (
608
611
& file,
609
612
& mut self . graph ,
610
613
& mut self . loaded_graphs ,
611
614
& self . conn ,
612
615
) ?;
613
- let path = serde_json :: from_slice :: < serde:: PartialPath > ( & json ) ?;
616
+ let path = rmp_serde :: from_slice :: < serde:: PartialPath > ( & value ) ?;
614
617
let path = path. to_partial_path ( & mut self . graph , & mut self . partials ) ?;
615
618
copious_debugging ! (
616
619
" > Loaded {}" ,
0 commit comments