Skip to content

Commit d3e8198

Browse files
committed
Replaced in-memory cache with file based cache in branches
1 parent 2c98c0c commit d3e8198

File tree

44 files changed

+4789
-1962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4789
-1962
lines changed

.talismanrc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
fileignoreconfig:
2-
- filename: package-lock.json
3-
checksum: 10993a3e930b77c3c6e09afcb50c23e6a8a901302172b699e92b0a4bfec0cffa
4-
- filename: pnpm-lock.yaml
5-
checksum: 3e47ed021491e9f3c21d25e4ea72a1101b51f16ebedd279019df1792b72417a4
6-
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
7-
checksum: 6e6fb00bb11b03141e5ad27eeaa4af9718dc30520c3e73970bc208cc0ba2a7d2
2+
- filename: pnpm-lock.yaml
3+
checksum: 8a476e69987ac9fda9f8b622cbbf3c35d0625654f0a8b0510e37d17af0b15948
4+
- filename: package-lock.json
5+
checksum: 001e74018a692910c4748816ae9d2ac06d0a105681b89d421a9e99481fb8196c
6+
- filename: packages/contentstack-branches/test/unit/commands/cm/branches/create.test.js
7+
checksum: ee5622594afb486aec7ffe3fa03162bee4e74bc6578358cb515636faaf79f0fd
8+
- filename: packages/contentstack-branches/test/unit/utils/interactive.test.js
9+
checksum: a11c00354f2c770ca2195c368bcaa35d5b2b857ff11edda55d820285f9b262ef
10+
- filename: packages/contentstack-branches/test/unit/commands/cm/branches/delete.test.js
11+
checksum: 9e62382be1b51f123563458b0ee7e530f8ce8cd81e3ddc4a7f709c5a15cdda5a
12+
- filename: packages/contentstack-branches/test/unit/utils/create-merge-scripts.test.js
13+
checksum: bec39d1d3fa042d388c3a5b1ddebd9aef7d970384a1fde7c40399bb7d5854585
14+
- filename: packages/contentstack-branches/src/branch/merge-handler.ts
15+
checksum: 5216f83ab87f3f0c20ee537b1fc16f9c9b3e980b6f4ddf8f8154c9f72dd6efda
16+
- filename: packages/contentstack-branches/test/unit/commands/cm/branches/list.test.js
17+
checksum: 33686e7e986ccc98e3c7fc2b1b6933b04714e0cff1e5b4254b863ff4c202e951
18+
- filename: packages/contentstack-branches/test/unit/utils/diff-branch-handler.test.js
19+
checksum: 83a9b67bfa5c0dd7a8f6735dac546da77ba49da592c2285e2fa7f7a17d4731ba
20+
- filename: packages/contentstack-branches/test/unit/mock/data.js
21+
checksum: 783c530873621536d5763dcc7e03f7fe23e324f0f4bb42244d28a85b9e936f75
822
version: '1.0'

package-lock.json

Lines changed: 1711 additions & 1691 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.17.1 darwin-arm64 node-v24.13.0
22+
@contentstack/cli-audit/1.18.0 darwin-arm64 node-v24.14.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND
@@ -309,7 +309,7 @@ EXAMPLES
309309
$ csdx plugins
310310
```
311311

312-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/index.ts)_
312+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/index.ts)_
313313

314314
## `csdx plugins:add PLUGIN`
315315

@@ -383,7 +383,7 @@ EXAMPLES
383383
$ csdx plugins:inspect myplugin
384384
```
385385

386-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/inspect.ts)_
386+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/inspect.ts)_
387387

388388
## `csdx plugins:install PLUGIN`
389389

@@ -432,7 +432,7 @@ EXAMPLES
432432
$ csdx plugins:install someuser/someplugin
433433
```
434434

435-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/install.ts)_
435+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/install.ts)_
436436

437437
## `csdx plugins:link PATH`
438438

@@ -463,7 +463,7 @@ EXAMPLES
463463
$ csdx plugins:link myplugin
464464
```
465465

466-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/link.ts)_
466+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/link.ts)_
467467

468468
## `csdx plugins:remove [PLUGIN]`
469469

@@ -504,7 +504,7 @@ FLAGS
504504
--reinstall Reinstall all plugins after uninstalling.
505505
```
506506

507-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/reset.ts)_
507+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/reset.ts)_
508508

509509
## `csdx plugins:uninstall [PLUGIN]`
510510

@@ -532,7 +532,7 @@ EXAMPLES
532532
$ csdx plugins:uninstall myplugin
533533
```
534534

535-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/uninstall.ts)_
535+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/uninstall.ts)_
536536

537537
## `csdx plugins:unlink [PLUGIN]`
538538

@@ -576,5 +576,5 @@ DESCRIPTION
576576
Update installed plugins.
577577
```
578578

579-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/update.ts)_
579+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/update.ts)_
580580
<!-- commandsstop -->

packages/contentstack-auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-auth/1.7.2 darwin-arm64 node-v24.13.0
21+
@contentstack/cli-auth/1.7.3 darwin-arm64 node-v24.14.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND

packages/contentstack-bootstrap/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
1515
$ csdx COMMAND
1616
running command...
1717
$ csdx (--version)
18-
@contentstack/cli-cm-bootstrap/1.18.2 darwin-arm64 node-v24.13.0
18+
@contentstack/cli-cm-bootstrap/1.18.4 darwin-arm64 node-v24.14.0
1919
$ csdx --help [COMMAND]
2020
USAGE
2121
$ csdx COMMAND

packages/contentstack-branches/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ For switching to AZURE-NA region update the hosts at config/default.js
2929
}
3030
```
3131

32+
## Branch compare cache
33+
34+
Large branch compares write temporary JSONL files under **`<current working directory>/.contentstack-branch-cache/`** (see `cacheDir` in `src/config`). The process needs a **writable working directory**. If disk writes fail, the CLI falls back to an in-memory compare and prints a warning (very large stacks may use more memory).
35+
3236
# Usage
3337

3438
<!-- usage -->
@@ -37,7 +41,7 @@ $ npm install -g @contentstack/cli-cm-branches
3741
$ csdx COMMAND
3842
running command...
3943
$ csdx (--version)
40-
@contentstack/cli-cm-branches/1.6.3 darwin-arm64 node-v24.13.0
44+
@contentstack/cli-cm-branches/1.7.0 darwin-arm64 node-v24.14.0
4145
$ csdx --help [COMMAND]
4246
USAGE
4347
$ csdx COMMAND

packages/contentstack-branches/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-cm-branches",
33
"description": "Contentstack CLI plugin to do branches operations",
4-
"version": "1.6.3",
4+
"version": "1.7.0",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
@@ -79,4 +79,4 @@
7979
}
8080
},
8181
"repository": "https://github.com/contentstack/cli"
82-
}
82+
}

packages/contentstack-branches/src/branch/diff-handler.ts

Lines changed: 125 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import startCase from 'lodash/startCase';
22
import camelCase from 'lodash/camelCase';
33
import { cliux } from '@contentstack/cli-utilities';
4-
import { getbranchConfig } from '../utils';
5-
import { BranchOptions, BranchDiffPayload } from '../interfaces';
4+
import { getbranchConfig, cleanupSession } from '../utils';
5+
import { BranchCompareCacheRef, BranchOptions, BranchCompactTextRes, BranchDiffPayload } from '../interfaces';
66
import { askBaseBranch, askCompareBranch, askStackAPIKey, selectModule } from '../utils/interactive';
77
import {
88
fetchBranchesDiff,
@@ -13,7 +13,14 @@ import {
1313
parseVerbose,
1414
printVerboseTextView,
1515
filterBranchDiffDataByModule,
16+
isBranchCompareCacheRef,
17+
isInlineBranchCompareResult,
18+
summaryFromCompact,
19+
flatCompactToRawArray,
20+
parseSummaryFromJsonlPath,
21+
printCompactTextViewFromJsonlModulePath,
1622
} from '../utils/branch-diff-utility';
23+
import { readAllJsonLines } from '../utils/cache-manager';
1724
import { exportCSVReport } from '../utils/csv-utility';
1825

1926
export default class BranchDiffHandler {
@@ -24,8 +31,15 @@ export default class BranchDiffHandler {
2431
}
2532

2633
async run(): Promise<any> {
27-
await this.validateMandatoryFlags();
28-
await this.initBranchDiffUtility();
34+
let cacheRef: BranchCompareCacheRef | undefined;
35+
try {
36+
await this.validateMandatoryFlags();
37+
cacheRef = await this.initBranchDiffUtility();
38+
} finally {
39+
if (cacheRef?.kind === 'cache') {
40+
await cleanupSession(cacheRef.sessionId).catch(() => undefined);
41+
}
42+
}
2943
}
3044

3145
/**
@@ -40,7 +54,7 @@ export default class BranchDiffHandler {
4054
}
4155

4256
if (!this.options.baseBranch) {
43-
baseBranch = getbranchConfig(this.options.stackAPIKey);
57+
baseBranch = getbranchConfig(this.options.stackAPIKey);
4458
if (!baseBranch) {
4559
this.options.baseBranch = await askBaseBranch();
4660
} else {
@@ -60,24 +74,24 @@ export default class BranchDiffHandler {
6074
this.options.csvPath = process.cwd();
6175
}
6276

63-
if(baseBranch){
77+
if (baseBranch) {
6478
cliux.print(`\nBase branch: ${baseBranch}`, { color: 'grey' });
6579
}
6680
}
6781

6882
/**
6983
* @methods initBranchDiffUtility - call utility function to load data and display it
70-
* @returns {*} {Promise<void>}
84+
* @returns {*} {Promise<BranchCompareCacheRef | undefined>}
7185
* @memberof BranchDiff
7286
*/
73-
async initBranchDiffUtility(): Promise<void> {
87+
async initBranchDiffUtility(): Promise<BranchCompareCacheRef | undefined> {
7488
const spinner = cliux.loaderV2('Loading branch differences...');
7589
const payload: BranchDiffPayload = {
7690
module: '',
7791
apiKey: this.options.stackAPIKey,
7892
baseBranch: this.options.baseBranch,
7993
compareBranch: this.options.compareBranch,
80-
host: this.options.host
94+
host: this.options.host,
8195
};
8296

8397
if (this.options.module === 'content-types') {
@@ -86,21 +100,107 @@ export default class BranchDiffHandler {
86100
payload.module = 'global_fields';
87101
}
88102
payload.spinner = spinner;
89-
const branchDiffData = await fetchBranchesDiff(payload);
90-
const diffData = filterBranchDiffDataByModule(branchDiffData);
103+
const fetchResult = await fetchBranchesDiff(payload);
91104
cliux.loaderV2('', spinner);
92-
93-
if(this.options.module === 'all'){
94-
for (let module in diffData) {
95-
const branchDiff = diffData[module];
96-
payload.module = module;
97-
this.displaySummary(branchDiff, module);
98-
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
99-
}
100-
}else{
101-
const branchDiff = diffData[payload.module];
102-
this.displaySummary(branchDiff, this.options.module);
105+
106+
if (isBranchCompareCacheRef(fetchResult)) {
107+
await this.displayFromCacheRef(fetchResult, payload);
108+
return fetchResult;
109+
}
110+
111+
if (isInlineBranchCompareResult(fetchResult)) {
112+
await this.displayFromInlineResult(fetchResult, payload);
113+
return undefined;
114+
}
115+
116+
const branchDiffData = fetchResult;
117+
const diffData = filterBranchDiffDataByModule(branchDiffData);
118+
119+
if (this.options.module === 'all') {
120+
for (const module in diffData) {
121+
const branchDiff = diffData[module];
122+
payload.module = module;
123+
this.displaySummary(branchDiff, module);
103124
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
125+
}
126+
} else {
127+
const branchDiff = diffData[payload.module];
128+
this.displaySummary(branchDiff, this.options.module);
129+
await this.displayBranchDiffTextAndVerbose(branchDiff, payload);
130+
}
131+
return undefined;
132+
}
133+
134+
private async displayFromCacheRef(cacheRef: BranchCompareCacheRef, payload: BranchDiffPayload): Promise<void> {
135+
const modulesToShow =
136+
this.options.module === 'all'
137+
? (['content_types', 'global_fields'] as const)
138+
: payload.module === 'content_types'
139+
? (['content_types'] as const)
140+
: (['global_fields'] as const);
141+
142+
for (const module of modulesToShow) {
143+
const modulePath = cacheRef.paths[module];
144+
const displayModule = module === 'content_types' ? 'content-types' : 'global-fields';
145+
payload.module = module;
146+
cliux.print(' ');
147+
cliux.print(`${startCase(camelCase(module))} Summary:`, { color: 'yellow' });
148+
const diffSummary = await parseSummaryFromJsonlPath(
149+
modulePath,
150+
this.options.baseBranch,
151+
this.options.compareBranch,
152+
);
153+
printSummary(diffSummary);
154+
const spinner1 = cliux.loaderV2('Loading branch differences...');
155+
if (this.options.format === 'compact-text') {
156+
cliux.loaderV2('', spinner1);
157+
await printCompactTextViewFromJsonlModulePath(modulePath);
158+
} else if (this.options.format === 'detailed-text') {
159+
const branchModuleData = await readAllJsonLines(modulePath);
160+
const verboseRes = await parseVerbose(branchModuleData, payload);
161+
cliux.loaderV2('', spinner1);
162+
printVerboseTextView(verboseRes);
163+
exportCSVReport(displayModule, verboseRes, this.options.csvPath);
164+
if (verboseRes.verboseCacheSessionId) {
165+
await cleanupSession(verboseRes.verboseCacheSessionId).catch(() => undefined);
166+
}
167+
}
168+
}
169+
}
170+
171+
private async displayFromInlineResult(
172+
inline: { content_types: BranchCompactTextRes; global_fields: BranchCompactTextRes },
173+
payload: BranchDiffPayload,
174+
): Promise<void> {
175+
const modulesToShow =
176+
this.options.module === 'all'
177+
? (['content_types', 'global_fields'] as const)
178+
: payload.module === 'content_types'
179+
? (['content_types'] as const)
180+
: (['global_fields'] as const);
181+
182+
for (const module of modulesToShow) {
183+
const compact = inline[module];
184+
const displayModule = module === 'content_types' ? 'content-types' : 'global-fields';
185+
payload.module = module;
186+
cliux.print(' ');
187+
cliux.print(`${startCase(camelCase(module))} Summary:`, { color: 'yellow' });
188+
const diffSummary = summaryFromCompact(compact, this.options.baseBranch, this.options.compareBranch);
189+
printSummary(diffSummary);
190+
const spinner1 = cliux.loaderV2('Loading branch differences...');
191+
if (this.options.format === 'compact-text') {
192+
cliux.loaderV2('', spinner1);
193+
printCompactTextView(compact);
194+
} else if (this.options.format === 'detailed-text') {
195+
const branchModuleData = flatCompactToRawArray(compact);
196+
const verboseRes = await parseVerbose(branchModuleData, payload);
197+
cliux.loaderV2('', spinner1);
198+
printVerboseTextView(verboseRes);
199+
exportCSVReport(displayModule, verboseRes, this.options.csvPath);
200+
if (verboseRes.verboseCacheSessionId) {
201+
await cleanupSession(verboseRes.verboseCacheSessionId).catch(() => undefined);
202+
}
203+
}
104204
}
105205
}
106206

@@ -133,6 +233,9 @@ export default class BranchDiffHandler {
133233
printVerboseTextView(verboseRes);
134234

135235
exportCSVReport(payload.module, verboseRes, this.options.csvPath);
236+
if (verboseRes.verboseCacheSessionId) {
237+
await cleanupSession(verboseRes.verboseCacheSessionId).catch(() => undefined);
238+
}
136239
}
137240
}
138241
}

0 commit comments

Comments
 (0)