Database performance improvements
This commit is contained in:
parent
2b8a7972a0
commit
273ecdfafc
@ -441,8 +441,8 @@ export class ApiService {
|
|||||||
for ( const rec of data.databaseEntries ) {
|
for ( const rec of data.databaseEntries ) {
|
||||||
const entry = new DatabaseEntry(
|
const entry = new DatabaseEntry(
|
||||||
rec.DatabaseId,
|
rec.DatabaseId,
|
||||||
JSON.stringify(rec.RowData || {}),
|
rec.UUID,
|
||||||
rec.UUID
|
JSON.stringify(rec.RowData || {})
|
||||||
);
|
);
|
||||||
|
|
||||||
await entry.save();
|
await entry.save();
|
||||||
@ -812,6 +812,9 @@ export class ApiService {
|
|||||||
|
|
||||||
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/data`).subscribe({
|
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/data`).subscribe({
|
||||||
next: async result => {
|
next: async result => {
|
||||||
|
// Resolve first so the GUI doesn't need to wait for the DB to sync to render
|
||||||
|
res(result.data);
|
||||||
|
|
||||||
for ( const row of result.data ) {
|
for ( const row of result.data ) {
|
||||||
const existingDatabaseEntry = await this.db.databaseEntries.where({
|
const existingDatabaseEntry = await this.db.databaseEntries.where({
|
||||||
DatabaseId, UUID: row.UUID,
|
DatabaseId, UUID: row.UUID,
|
||||||
@ -823,15 +826,13 @@ export class ApiService {
|
|||||||
} else {
|
} else {
|
||||||
const newDatabaseEntry = new DatabaseEntry(
|
const newDatabaseEntry = new DatabaseEntry(
|
||||||
row.DatabaseId,
|
row.DatabaseId,
|
||||||
JSON.stringify(row.RowData),
|
row.UUID,
|
||||||
row.UUID
|
JSON.stringify(row.RowData)
|
||||||
);
|
);
|
||||||
|
|
||||||
await newDatabaseEntry.save();
|
await newDatabaseEntry.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res(result.data);
|
|
||||||
},
|
},
|
||||||
error: rej,
|
error: rej,
|
||||||
});
|
});
|
||||||
@ -849,6 +850,9 @@ export class ApiService {
|
|||||||
// If online, fetch the columns and sync the local database
|
// If online, fetch the columns and sync the local database
|
||||||
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns`).subscribe({
|
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns`).subscribe({
|
||||||
next: async results => {
|
next: async results => {
|
||||||
|
// Resolve this first, so the UI doesn't need to wait for the db sync to render
|
||||||
|
res(results.data);
|
||||||
|
|
||||||
for ( const def of results.data ) {
|
for ( const def of results.data ) {
|
||||||
const existingColumnDef = await this.db.databaseColumns.where({
|
const existingColumnDef = await this.db.databaseColumns.where({
|
||||||
DatabaseId, UUID: def.UUID,
|
DatabaseId, UUID: def.UUID,
|
||||||
@ -870,8 +874,6 @@ export class ApiService {
|
|||||||
await newColumnDef.save();
|
await newColumnDef.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res(results.data);
|
|
||||||
},
|
},
|
||||||
error: rej,
|
error: rej,
|
||||||
});
|
});
|
||||||
@ -968,8 +970,8 @@ export class ApiService {
|
|||||||
for ( const row of rowData ) {
|
for ( const row of rowData ) {
|
||||||
const newDatabaseEntry = new DatabaseEntry(
|
const newDatabaseEntry = new DatabaseEntry(
|
||||||
DatabaseId,
|
DatabaseId,
|
||||||
JSON.stringify(row),
|
|
||||||
DatabaseEntry.getUUID(),
|
DatabaseEntry.getUUID(),
|
||||||
|
JSON.stringify(row),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -987,8 +989,8 @@ export class ApiService {
|
|||||||
for ( const row of result.data ) {
|
for ( const row of result.data ) {
|
||||||
const newDatabaseEntry = new DatabaseEntry(
|
const newDatabaseEntry = new DatabaseEntry(
|
||||||
row.DatabaseId,
|
row.DatabaseId,
|
||||||
JSON.stringify(row.RowData),
|
row.UUID,
|
||||||
row.UUID
|
JSON.stringify(row.RowData)
|
||||||
);
|
);
|
||||||
|
|
||||||
await newDatabaseEntry.save();
|
await newDatabaseEntry.save();
|
||||||
|
@ -30,7 +30,7 @@ export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseC
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static getSchema() {
|
public static getSchema() {
|
||||||
return '++id, headerName, field, DatabaseId, UUID, Type, additionalData, needsServerUpdate, deleted, offlineUpdatedAt';
|
return '++id, headerName, field, [DatabaseId+UUID], Type, additionalData, needsServerUpdate, deleted, offlineUpdatedAt';
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -24,13 +24,13 @@ export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEnt
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static getSchema() {
|
public static getSchema() {
|
||||||
return '++id, DatabaseId, RowDataJSON, UUID, needsServerUpdate, deleted, offlineUpdatedAt';
|
return '++id, [DatabaseId+UUID], RowDataJSON, needsServerUpdate, deleted, offlineUpdatedAt';
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
DatabaseId: string,
|
DatabaseId: string,
|
||||||
RowDataJSON: string,
|
|
||||||
UUID: string,
|
UUID: string,
|
||||||
|
RowDataJSON: string,
|
||||||
needsServerUpdate?: boolean,
|
needsServerUpdate?: boolean,
|
||||||
deleted?: boolean,
|
deleted?: boolean,
|
||||||
offlineUpdatedAt?: string,
|
offlineUpdatedAt?: string,
|
||||||
|
@ -63,7 +63,7 @@ export class DatabaseService extends Dexie {
|
|||||||
schema[ModelClass.getTableName()] = ModelClass.getSchema();
|
schema[ModelClass.getTableName()] = ModelClass.getSchema();
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.version(15).stores(schema);
|
await this.version(17).stores(schema);
|
||||||
await this.open();
|
await this.open();
|
||||||
|
|
||||||
this.migrations = this.table('migrations');
|
this.migrations = this.table('migrations');
|
||||||
|
Loading…
Reference in New Issue
Block a user