Performance updates
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
# Version 3.0.7
|
||||
# Version 3.0.8
|
||||
|
||||
- **Fixed** Slight performance improvement when importing data.
|
||||
|
||||
## Version 3.0.7
|
||||
|
||||
- **Fixed** SCHEMA_SYNC_DATA_ONLY being the opposite of what it should be.
|
||||
|
||||
|
||||
@@ -82,8 +82,12 @@ class CollectionExporter implements IExporter {
|
||||
public export = () => this._persistQueue();
|
||||
|
||||
public async load(merge = false) {
|
||||
if (await ExportHelper.fileExists(this.filePath)) {
|
||||
const json = await readFile(this.filePath, { encoding: 'utf8' });
|
||||
let json;
|
||||
try {
|
||||
json = await readFile(this.filePath, { encoding: 'utf8' });
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!json) {
|
||||
throw new Error(`Collection ${this.name} has invalid content: ${json}`);
|
||||
@@ -99,9 +103,6 @@ class CollectionExporter implements IExporter {
|
||||
return await this.loadGroupedItems(parsedJSON, merge);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected exportCollectionToFile = async () => {
|
||||
const items = await this.getItemsForExport();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SchemaOverview } from '@directus/types';
|
||||
import { HookConfig } from '@directus/extensions';
|
||||
import type { HookConfig } from '@directus/extensions';
|
||||
import type { SchemaOverview } from '@directus/types';
|
||||
import { condenseAction } from './condenseAction';
|
||||
import { copyConfig } from './copyConfig';
|
||||
import { ExportManager } from './exportManager';
|
||||
|
||||
@@ -29,9 +29,7 @@ export class SchemaExporter implements IExporter {
|
||||
} else {
|
||||
// Clean up old schema files
|
||||
const files = await glob(this.schemaFilesPath('*'));
|
||||
for (const file of files) {
|
||||
await rm(file);
|
||||
}
|
||||
await Promise.all(files.map(file => rm(file)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,8 +48,12 @@ export class SchemaExporter implements IExporter {
|
||||
*/
|
||||
public load = async () => {
|
||||
const svc = this._getSchemaService();
|
||||
if (await ExportHelper.fileExists(this._filePath)) {
|
||||
const json = await readFile(this._filePath, { encoding: 'utf8' });
|
||||
let json;
|
||||
try {
|
||||
json = await readFile(this._filePath, { encoding: 'utf8' });
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
if (json) {
|
||||
const schemaParsed = JSON.parse(json);
|
||||
// For older versions, the snapshot was stored under the key `snapshot`
|
||||
@@ -68,7 +70,7 @@ export class SchemaExporter implements IExporter {
|
||||
|
||||
let found = 0;
|
||||
const files = await glob(this.schemaFilesPath('*'));
|
||||
for (const file of files) {
|
||||
await Promise.all(files.map(async (file) => {
|
||||
const collectionJson = await readFile(file, { encoding: 'utf8' });
|
||||
const { fields, relations, ...collectionInfo } = JSON.parse(collectionJson) as Collection & {
|
||||
fields: SnapshotField[];
|
||||
@@ -87,7 +89,7 @@ export class SchemaExporter implements IExporter {
|
||||
for (const relation of relations) {
|
||||
snapshot.relations.push(Object.assign({ collection: collectionInfo.collection }, relation));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
if (found === 0) {
|
||||
this.logger.error('No schema files found in schema directory');
|
||||
@@ -116,7 +118,6 @@ export class SchemaExporter implements IExporter {
|
||||
await svc.apply({ diff, hash: currentHash });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -170,10 +171,11 @@ export class SchemaExporter implements IExporter {
|
||||
await writeFile(this._filePath, schemaJson);
|
||||
|
||||
// Save all collections with fields as individual files
|
||||
for (const [collection, item] of Object.entries(map)) {
|
||||
const itemJson = JSON.stringify(item, null, 2);
|
||||
await writeFile(this.schemaFilesPath(collection), itemJson);
|
||||
}
|
||||
await Promise.all(
|
||||
Object.entries(map).map(([collection, item]) =>
|
||||
writeFile(this.schemaFilesPath(collection), JSON.stringify(item, null, 2))
|
||||
)
|
||||
);
|
||||
} else {
|
||||
const schemaJson = JSON.stringify(Object.assign({ hash }, snapshot), null, 2);
|
||||
await writeFile(this._filePath, schemaJson);
|
||||
|
||||
@@ -60,7 +60,7 @@ export class ExportHelper {
|
||||
}
|
||||
|
||||
static async getExportMeta() {
|
||||
if (await this.fileExists(this.hashFile)) {
|
||||
try {
|
||||
const content = await readFile(this.hashFile, { encoding: 'utf8' });
|
||||
const [hash, ts] = content.split('@');
|
||||
|
||||
@@ -70,8 +70,9 @@ export class ExportHelper {
|
||||
ts,
|
||||
};
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user