@@ -14,6 +14,15 @@ use crate::native::cache::file_ops::_copy;
1414use crate :: native:: db:: connection:: NxDbConnection ;
1515use crate :: native:: utils:: Normalize ;
1616
17+ pub const SCHEMA : & str = "CREATE TABLE IF NOT EXISTS cache_outputs (
18+ hash TEXT PRIMARY KEY NOT NULL,
19+ code INTEGER NOT NULL,
20+ size INTEGER NOT NULL,
21+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
22+ accessed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
23+ FOREIGN KEY (hash) REFERENCES task_details (hash)
24+ );" ;
25+
1726#[ napi( object) ]
1827#[ derive( Default , Clone , Debug ) ]
1928pub struct CachedResult {
@@ -29,7 +38,6 @@ pub struct NxCache {
2938 workspace_root : PathBuf ,
3039 cache_path : PathBuf ,
3140 db : External < NxDbConnection > ,
32- link_task_details : bool ,
3341 max_cache_size : i64 ,
3442}
3543
@@ -40,7 +48,6 @@ impl NxCache {
4048 workspace_root : String ,
4149 cache_path : String ,
4250 db_connection : External < NxDbConnection > ,
43- link_task_details : Option < bool > ,
4451 max_cache_size : Option < i64 > ,
4552 ) -> anyhow:: Result < Self > {
4653 let cache_path = PathBuf :: from ( & cache_path) ;
@@ -50,44 +57,13 @@ impl NxCache {
5057
5158 let max_cache_size = max_cache_size. unwrap_or ( 0 ) ;
5259
53- let r = Self {
60+ Ok ( Self {
5461 db : db_connection,
5562 workspace_root : PathBuf :: from ( workspace_root) ,
5663 cache_directory : cache_path. to_normalized_string ( ) ,
5764 cache_path,
58- link_task_details : link_task_details. unwrap_or ( true ) ,
5965 max_cache_size,
60- } ;
61-
62- r. setup ( ) ?;
63-
64- Ok ( r)
65- }
66-
67- fn setup ( & self ) -> anyhow:: Result < ( ) > {
68- let query = if self . link_task_details {
69- "CREATE TABLE IF NOT EXISTS cache_outputs (
70- hash TEXT PRIMARY KEY NOT NULL,
71- code INTEGER NOT NULL,
72- size INTEGER NOT NULL,
73- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
74- accessed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
75- FOREIGN KEY (hash) REFERENCES task_details (hash)
76- );
77- "
78- } else {
79- "CREATE TABLE IF NOT EXISTS cache_outputs (
80- hash TEXT PRIMARY KEY NOT NULL,
81- code INTEGER NOT NULL,
82- size INTEGER NOT NULL,
83- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
84- accessed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
85- );
86- "
87- } ;
88-
89- self . db . execute ( query, [ ] ) . map_err ( anyhow:: Error :: from) ?;
90- Ok ( ( ) )
66+ } )
9167 }
9268
9369 #[ napi]
0 commit comments