Database performance improvements
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

master
Garrett Mills 3 years ago
parent 2b8a7972a0
commit 273ecdfafc
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -441,8 +441,8 @@ export class ApiService {
for ( const rec of data.databaseEntries ) {
const entry = new DatabaseEntry(
rec.DatabaseId,
JSON.stringify(rec.RowData || {}),
rec.UUID
rec.UUID,
JSON.stringify(rec.RowData || {})
);
await entry.save();
@ -812,6 +812,9 @@ export class ApiService {
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/data`).subscribe({
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 ) {
const existingDatabaseEntry = await this.db.databaseEntries.where({
DatabaseId, UUID: row.UUID,
@ -823,15 +826,13 @@ export class ApiService {
} else {
const newDatabaseEntry = new DatabaseEntry(
row.DatabaseId,
JSON.stringify(row.RowData),
row.UUID
row.UUID,
JSON.stringify(row.RowData)
);
await newDatabaseEntry.save();
}
}
return res(result.data);
},
error: rej,
});
@ -849,6 +850,9 @@ export class ApiService {
// If online, fetch the columns and sync the local database
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns`).subscribe({
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 ) {
const existingColumnDef = await this.db.databaseColumns.where({
DatabaseId, UUID: def.UUID,
@ -870,8 +874,6 @@ export class ApiService {
await newColumnDef.save();
}
}
return res(results.data);
},
error: rej,
});
@ -968,8 +970,8 @@ export class ApiService {
for ( const row of rowData ) {
const newDatabaseEntry = new DatabaseEntry(
DatabaseId,
JSON.stringify(row),
DatabaseEntry.getUUID(),
JSON.stringify(row),
true
);
@ -987,8 +989,8 @@ export class ApiService {
for ( const row of result.data ) {
const newDatabaseEntry = new DatabaseEntry(
row.DatabaseId,
JSON.stringify(row.RowData),
row.UUID
row.UUID,
JSON.stringify(row.RowData)
);
await newDatabaseEntry.save();

@ -30,7 +30,7 @@ export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseC
}
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(

@ -24,13 +24,13 @@ export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEnt
}
public static getSchema() {
return '++id, DatabaseId, RowDataJSON, UUID, needsServerUpdate, deleted, offlineUpdatedAt';
return '++id, [DatabaseId+UUID], RowDataJSON, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
DatabaseId: string,
RowDataJSON: string,
UUID: string,
RowDataJSON: string,
needsServerUpdate?: boolean,
deleted?: boolean,
offlineUpdatedAt?: string,

@ -63,7 +63,7 @@ export class DatabaseService extends Dexie {
schema[ModelClass.getTableName()] = ModelClass.getSchema();
}
await this.version(15).stores(schema);
await this.version(17).stores(schema);
await this.open();
this.migrations = this.table('migrations');

Loading…
Cancel
Save