fix(core): allow creating a db cache without linking task details (#28023)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The db cache does not work without task details. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The db cache works without task details. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
7af099c828
commit
a510b3642d
28
packages/nx/src/native/cache/cache.rs
vendored
28
packages/nx/src/native/cache/cache.rs
vendored
@ -26,6 +26,7 @@ pub struct NxCache {
|
|||||||
workspace_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
cache_path: PathBuf,
|
cache_path: PathBuf,
|
||||||
db: External<Connection>,
|
db: External<Connection>,
|
||||||
|
link_task_details: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
@ -35,6 +36,7 @@ impl NxCache {
|
|||||||
workspace_root: String,
|
workspace_root: String,
|
||||||
cache_path: String,
|
cache_path: String,
|
||||||
db_connection: External<Connection>,
|
db_connection: External<Connection>,
|
||||||
|
link_task_details: Option<bool>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
let cache_path = PathBuf::from(&cache_path);
|
let cache_path = PathBuf::from(&cache_path);
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ impl NxCache {
|
|||||||
workspace_root: PathBuf::from(workspace_root),
|
workspace_root: PathBuf::from(workspace_root),
|
||||||
cache_directory: cache_path.to_normalized_string(),
|
cache_directory: cache_path.to_normalized_string(),
|
||||||
cache_path,
|
cache_path,
|
||||||
|
link_task_details: link_task_details.unwrap_or(true)
|
||||||
};
|
};
|
||||||
|
|
||||||
r.setup()?;
|
r.setup()?;
|
||||||
@ -54,9 +57,8 @@ impl NxCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setup(&self) -> anyhow::Result<()> {
|
fn setup(&self) -> anyhow::Result<()> {
|
||||||
self.db
|
let query = if self.link_task_details {
|
||||||
.execute_batch(
|
"BEGIN;
|
||||||
"BEGIN;
|
|
||||||
CREATE TABLE IF NOT EXISTS cache_outputs (
|
CREATE TABLE IF NOT EXISTS cache_outputs (
|
||||||
hash TEXT PRIMARY KEY NOT NULL,
|
hash TEXT PRIMARY KEY NOT NULL,
|
||||||
code INTEGER NOT NULL,
|
code INTEGER NOT NULL,
|
||||||
@ -64,8 +66,23 @@ impl NxCache {
|
|||||||
accessed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
accessed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (hash) REFERENCES task_details (hash)
|
FOREIGN KEY (hash) REFERENCES task_details (hash)
|
||||||
);
|
);
|
||||||
COMMIT;
|
COMMIT;
|
||||||
",
|
"
|
||||||
|
} else {
|
||||||
|
"BEGIN;
|
||||||
|
CREATE TABLE IF NOT EXISTS cache_outputs (
|
||||||
|
hash TEXT PRIMARY KEY NOT NULL,
|
||||||
|
code INTEGER NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
accessed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
COMMIT;
|
||||||
|
"
|
||||||
|
};
|
||||||
|
|
||||||
|
self.db
|
||||||
|
.execute_batch(
|
||||||
|
query,
|
||||||
)
|
)
|
||||||
.map_err(anyhow::Error::from)
|
.map_err(anyhow::Error::from)
|
||||||
}
|
}
|
||||||
@ -115,6 +132,7 @@ impl NxCache {
|
|||||||
outputs: Vec<String>,
|
outputs: Vec<String>,
|
||||||
code: i16,
|
code: i16,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
trace!("PUT {}", &hash);
|
||||||
let task_dir = self.cache_path.join(&hash);
|
let task_dir = self.cache_path.join(&hash);
|
||||||
|
|
||||||
// Remove the task directory
|
// Remove the task directory
|
||||||
|
|||||||
2
packages/nx/src/native/index.d.ts
vendored
2
packages/nx/src/native/index.d.ts
vendored
@ -28,7 +28,7 @@ export declare class ImportResult {
|
|||||||
|
|
||||||
export declare class NxCache {
|
export declare class NxCache {
|
||||||
cacheDirectory: string
|
cacheDirectory: string
|
||||||
constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<Connection>)
|
constructor(workspaceRoot: string, cachePath: string, dbConnection: ExternalObject<Connection>, linkTaskDetails?: boolean | undefined | null)
|
||||||
get(hash: string): CachedResult | null
|
get(hash: string): CachedResult | null
|
||||||
put(hash: string, terminalOutput: string, outputs: Array<string>, code: number): void
|
put(hash: string, terminalOutput: string, outputs: Array<string>, code: number): void
|
||||||
applyRemoteCacheResults(hash: string, result: CachedResult): void
|
applyRemoteCacheResults(hash: string, result: CachedResult): void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user