feat(core): enable db cache by default (#28048)
<!-- 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 DB cache is disabled by default ## Expected Behavior DB cache is enabled by default ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
d477ea7b6a
commit
d5c452194f
@ -23,7 +23,6 @@ Nx.json configuration
|
||||
- [cli](../../devkit/documents/NxJsonConfiguration#cli): Object
|
||||
- [defaultBase](../../devkit/documents/NxJsonConfiguration#defaultbase): string
|
||||
- [defaultProject](../../devkit/documents/NxJsonConfiguration#defaultproject): string
|
||||
- [enableDbCache](../../devkit/documents/NxJsonConfiguration#enabledbcache): boolean
|
||||
- [extends](../../devkit/documents/NxJsonConfiguration#extends): string
|
||||
- [generators](../../devkit/documents/NxJsonConfiguration#generators): Object
|
||||
- [implicitDependencies](../../devkit/documents/NxJsonConfiguration#implicitdependencies): ImplicitDependencyEntry<T>
|
||||
@ -43,6 +42,7 @@ Nx.json configuration
|
||||
- [tasksRunnerOptions](../../devkit/documents/NxJsonConfiguration#tasksrunneroptions): Object
|
||||
- [useDaemonProcess](../../devkit/documents/NxJsonConfiguration#usedaemonprocess): boolean
|
||||
- [useInferencePlugins](../../devkit/documents/NxJsonConfiguration#useinferenceplugins): boolean
|
||||
- [useLegacyCache](../../devkit/documents/NxJsonConfiguration#uselegacycache): boolean
|
||||
- [workspaceLayout](../../devkit/documents/NxJsonConfiguration#workspacelayout): Object
|
||||
|
||||
## Properties
|
||||
@ -99,14 +99,6 @@ will be used. Convenient for small workspaces with one main application.
|
||||
|
||||
---
|
||||
|
||||
### enableDbCache
|
||||
|
||||
• `Optional` **enableDbCache**: `boolean`
|
||||
|
||||
Enable the new experimental db based cache
|
||||
|
||||
---
|
||||
|
||||
### extends
|
||||
|
||||
• `Optional` **extends**: `string`
|
||||
@ -297,6 +289,14 @@ Set this to false to disable adding inference plugins when generating new projec
|
||||
|
||||
---
|
||||
|
||||
### useLegacyCache
|
||||
|
||||
• `Optional` **useLegacyCache**: `boolean`
|
||||
|
||||
Use the legacy file system cache instead of the db cache
|
||||
|
||||
---
|
||||
|
||||
### workspaceLayout
|
||||
|
||||
• `Optional` **workspaceLayout**: `Object`
|
||||
|
||||
@ -21,7 +21,6 @@ use ProjectsConfigurations or NxJsonConfiguration
|
||||
- [cli](../../devkit/documents/Workspace#cli): Object
|
||||
- [defaultBase](../../devkit/documents/Workspace#defaultbase): string
|
||||
- [defaultProject](../../devkit/documents/Workspace#defaultproject): string
|
||||
- [enableDbCache](../../devkit/documents/Workspace#enabledbcache): boolean
|
||||
- [extends](../../devkit/documents/Workspace#extends): string
|
||||
- [generators](../../devkit/documents/Workspace#generators): Object
|
||||
- [implicitDependencies](../../devkit/documents/Workspace#implicitdependencies): ImplicitDependencyEntry<string[] | "\*">
|
||||
@ -42,6 +41,7 @@ use ProjectsConfigurations or NxJsonConfiguration
|
||||
- [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions): Object
|
||||
- [useDaemonProcess](../../devkit/documents/Workspace#usedaemonprocess): boolean
|
||||
- [useInferencePlugins](../../devkit/documents/Workspace#useinferenceplugins): boolean
|
||||
- [useLegacyCache](../../devkit/documents/Workspace#uselegacycache): boolean
|
||||
- [version](../../devkit/documents/Workspace#version): number
|
||||
- [workspaceLayout](../../devkit/documents/Workspace#workspacelayout): Object
|
||||
|
||||
@ -119,18 +119,6 @@ will be used. Convenient for small workspaces with one main application.
|
||||
|
||||
---
|
||||
|
||||
### enableDbCache
|
||||
|
||||
• `Optional` **enableDbCache**: `boolean`
|
||||
|
||||
Enable the new experimental db based cache
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[enableDbCache](../../devkit/documents/NxJsonConfiguration#enabledbcache)
|
||||
|
||||
---
|
||||
|
||||
### extends
|
||||
|
||||
• `Optional` **extends**: `string`
|
||||
@ -409,6 +397,18 @@ Set this to false to disable adding inference plugins when generating new projec
|
||||
|
||||
---
|
||||
|
||||
### useLegacyCache
|
||||
|
||||
• `Optional` **useLegacyCache**: `boolean`
|
||||
|
||||
Use the legacy file system cache instead of the db cache
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[useLegacyCache](../../devkit/documents/NxJsonConfiguration#uselegacycache)
|
||||
|
||||
---
|
||||
|
||||
### version
|
||||
|
||||
• **version**: `number`
|
||||
|
||||
@ -80,7 +80,7 @@ export const allowedWorkspaceExtensions = [
|
||||
'useInferencePlugins',
|
||||
'neverConnectToCloud',
|
||||
'sync',
|
||||
'enableDbCache',
|
||||
'useLegacyCache',
|
||||
] as const;
|
||||
|
||||
if (!patched) {
|
||||
|
||||
@ -517,9 +517,9 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
|
||||
sync?: NxSyncConfiguration;
|
||||
|
||||
/**
|
||||
* Enable the new experimental db based cache
|
||||
* Use the legacy file system cache instead of the db cache
|
||||
*/
|
||||
enableDbCache?: boolean;
|
||||
useLegacyCache?: boolean;
|
||||
}
|
||||
|
||||
export type PluginConfiguration = string | ExpandedPluginConfiguration;
|
||||
|
||||
11
packages/nx/src/native/cache/cache.rs
vendored
11
packages/nx/src/native/cache/cache.rs
vendored
@ -136,12 +136,17 @@ impl NxCache {
|
||||
let task_dir = self.cache_path.join(&hash);
|
||||
|
||||
// Remove the task directory
|
||||
//
|
||||
trace!("Removing task directory: {:?}", &task_dir);
|
||||
remove_items(&[&task_dir])?;
|
||||
// Create the task directory again
|
||||
trace!("Creating task directory: {:?}", &task_dir);
|
||||
create_dir_all(&task_dir)?;
|
||||
|
||||
// Write the terminal outputs into a file
|
||||
write(self.get_task_outputs_path_internal(&hash), terminal_output)?;
|
||||
let task_outputs_path: _ = self.get_task_outputs_path_internal(&hash);
|
||||
trace!("Writing terminal outputs to: {:?}", &task_outputs_path);
|
||||
write(task_outputs_path, terminal_output)?;
|
||||
|
||||
// Expand the outputs
|
||||
let expanded_outputs = _expand_outputs(&self.workspace_root, outputs)?;
|
||||
@ -151,10 +156,12 @@ impl NxCache {
|
||||
let p = self.workspace_root.join(expanded_output);
|
||||
if p.exists() {
|
||||
let cached_outputs_dir = task_dir.join(expanded_output);
|
||||
trace!("Copying {:?} -> {:?}", &p, &cached_outputs_dir);
|
||||
_copy(p, cached_outputs_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
trace!("Recording to cache: {:?}", &hash);
|
||||
self.record_to_cache(hash, code)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -269,7 +276,7 @@ impl NxCache {
|
||||
let entry = entry?;
|
||||
let is_dir = entry.file_type()?.is_dir();
|
||||
|
||||
if (is_dir) {
|
||||
if is_dir {
|
||||
if let Some(file_name) = entry.file_name().to_str() {
|
||||
if hash_regex.is_match(file_name) {
|
||||
return Ok(false);
|
||||
|
||||
19
packages/nx/src/native/cache/file_ops.rs
vendored
19
packages/nx/src/native/cache/file_ops.rs
vendored
@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::{fs, io};
|
||||
|
||||
use fs_extra::error::ErrorKind;
|
||||
use tracing::trace;
|
||||
|
||||
#[napi]
|
||||
pub fn remove(src: String) -> anyhow::Result<()> {
|
||||
@ -17,7 +18,8 @@ pub fn copy(src: String, dest: String) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
pub fn _copy<P>(src: P, dest: P) -> anyhow::Result<()> where P: AsRef<Path> {
|
||||
let dest: PathBuf = dest.as_ref().into();
|
||||
let dest: PathBuf = remove_trailing_single_dot(dest);
|
||||
|
||||
let dest_parent = dest.parent().unwrap_or(&dest);
|
||||
|
||||
let src: PathBuf = src.as_ref().into();
|
||||
@ -37,6 +39,18 @@ pub fn _copy<P>(src: P, dest: P) -> anyhow::Result<()> where P: AsRef<Path> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove_trailing_single_dot(path: impl AsRef<Path>) -> PathBuf {
|
||||
let mut components = path.as_ref().components().collect::<Vec<_>>();
|
||||
|
||||
if let Some(last_component) = components.last() {
|
||||
if last_component.as_os_str() == "." {
|
||||
components.pop();
|
||||
}
|
||||
}
|
||||
|
||||
components.iter().collect()
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
|
||||
std::os::windows::fs::symlink_file(original, link)
|
||||
@ -53,7 +67,10 @@ fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<(
|
||||
}
|
||||
|
||||
fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
|
||||
|
||||
trace!("creating directory: {:?}", dst.as_ref());
|
||||
fs::create_dir_all(&dst)?;
|
||||
trace!("reading source directory: {:?}", src.as_ref());
|
||||
for entry in fs::read_dir(src)? {
|
||||
let entry = entry?;
|
||||
let ty = entry.file_type()?;
|
||||
|
||||
@ -32,7 +32,8 @@ export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult };
|
||||
export function dbCacheEnabled(nxJson: NxJsonConfiguration = readNxJson()) {
|
||||
return (
|
||||
process.env.NX_DISABLE_DB !== 'true' &&
|
||||
(nxJson.enableDbCache === true || process.env.NX_DB_CACHE === 'true')
|
||||
nxJson.useLegacyCache !== true &&
|
||||
process.env.NX_DB_CACHE !== 'false'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user