Browse Source

Database performance improvements

master
Garrett Mills 3 months ago
parent
commit
273ecdfafc
Signed by: garrettmills GPG Key ID: D2BF5FBA8298F246
4 changed files with 17 additions and 15 deletions
  1. +13
    -11
      src/app/service/api.service.ts
  2. +1
    -1
      src/app/service/db/DatabaseColumn.ts
  3. +2
    -2
      src/app/service/db/DatabaseEntry.ts
  4. +1
    -1
      src/app/service/db/database.service.ts

+ 13
- 11
src/app/service/api.service.ts View File

@ -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();


+ 1
- 1
src/app/service/db/DatabaseColumn.ts View File

@ -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(


+ 2
- 2
src/app/service/db/DatabaseEntry.ts View File

@ -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,


+ 1
- 1
src/app/service/db/database.service.ts View File

@ -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