Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clear cache before process #40

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"typescript": "5.4.2"
},
"dependencies": {
"@directus/sdk": "^15.0.2",
"@directus/sdk": "^15.0.3",
"commander": "^12.0.0",
"deep-object-diff": "^1.1.9",
"deepmerge": "^4.3.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/lib/commands/diff.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Container } from 'typedi';
import { SnapshotClient } from '../services';
import { MigrationClient, SnapshotClient } from '../services';
import { loadCollections } from '../loader';

export async function runDiff() {
// Clear the cache
await Container.get(MigrationClient).clearCache();
// Snapshot
await Container.get(SnapshotClient).diff();

Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/lib/commands/pull.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Container } from 'typedi';
import { SnapshotClient, SpecificationsClient } from '../services';
import {
MigrationClient,
SnapshotClient,
SpecificationsClient,
} from '../services';
import { loadCollections } from '../loader';

export async function runPull() {
// Clear the cache
await Container.get(MigrationClient).clearCache();

// Snapshot
await Container.get(SnapshotClient).pull();

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/lib/commands/push.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Container } from 'typedi';
import pino from 'pino';
import { SnapshotClient } from '../services';
import { MigrationClient, SnapshotClient } from '../services';
import { loadCollections } from '../loader';
import { LOGGER } from '../constants';

export async function runPush() {
const logger: pino.Logger = Container.get(LOGGER);

// Clear the cache
await Container.get(MigrationClient).clearCache();

// Snapshot
logger.info(`---- Push schema ----`);
await Container.get(SnapshotClient).push();
Expand Down
19 changes: 17 additions & 2 deletions packages/cli/src/lib/services/migration-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
authentication,
AuthenticationClient,
clearCache,
createDirectus,
DirectusClient,
readMe,
Expand All @@ -11,9 +12,12 @@ import { Inject, Service } from 'typedi';
import pino from 'pino';
import { LOGGER } from '../constants';
import { ConfigService, isDirectusConfigWithToken } from './config';
import { getChildLogger } from '../helpers';

@Service()
export class MigrationClient {
protected readonly logger: pino.Logger;

protected adminRoleId: string | undefined;

protected client:
Expand All @@ -24,8 +28,10 @@ export class MigrationClient {

constructor(
protected readonly config: ConfigService,
@Inject(LOGGER) protected readonly logger: pino.Logger,
) {}
@Inject(LOGGER) baseLogger: pino.Logger,
) {
this.logger = getChildLogger(baseLogger, 'migration-client');
}

async get() {
if (!this.client) {
Expand All @@ -50,6 +56,15 @@ export class MigrationClient {
return this.adminRoleId;
}

/**
* This method clears the cache of the Directus instance
*/
async clearCache() {
const directus = await this.get();
await directus.request(clearCache());
this.logger.debug('Cache cleared');
}

protected async createClient() {
const config = this.config.getDirectusConfig();
const client = createDirectus(config.url)
Expand Down
Loading