Implement a new method to add multiple rows simultaneously without rerenders in-between the row additions
This commit is contained in:
parent
bb4c24329a
commit
8b488f488b
2 changed files with 28 additions and 4 deletions
|
|
@ -62,10 +62,14 @@ export class Database {
|
||||||
};
|
};
|
||||||
|
|
||||||
// MARK: Row Ops
|
// MARK: Row Ops
|
||||||
static createRow(table, userID, row) {
|
static createRow(table, userID, row, opts) {
|
||||||
throw new Error(`createRow() must be implemented`);
|
throw new Error(`createRow() must be implemented`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static createRows(table, userID, rows, opts) {
|
||||||
|
throw new Error(`createRows() must be implemented`);
|
||||||
|
};
|
||||||
|
|
||||||
static getRows(tableID, userIDs, privacy = `none`) {
|
static getRows(tableID, userIDs, privacy = `none`) {
|
||||||
throw new Error(`getRows() must be implemented`);
|
throw new Error(`getRows() must be implemented`);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { Database } from "./Database.mjs";
|
import { Database } from "./Database.mjs";
|
||||||
import { filterPrivateRows } from "../filterPrivateRows.mjs";
|
import { filterPrivateRows } from "../privacy.mjs";
|
||||||
|
import { Logger } from "../Logger.mjs";
|
||||||
|
|
||||||
const { randomID, mergeObject } = foundry.utils;
|
const { randomID, mergeObject } = foundry.utils;
|
||||||
|
|
||||||
|
|
@ -89,16 +90,35 @@ export class MemoryDatabase extends Database {
|
||||||
return this.#tables[tableID];
|
return this.#tables[tableID];
|
||||||
};
|
};
|
||||||
|
|
||||||
static createRow(table, userID, row) {
|
static createRow(table, userID, row, { rerender = true } = {}) {
|
||||||
if (!this.#tables[table]) { return };
|
if (!this.#tables[table]) { return };
|
||||||
this.#rows[userID] ??= {};
|
this.#rows[userID] ??= {};
|
||||||
this.#rows[userID][table] ??= [];
|
this.#rows[userID][table] ??= [];
|
||||||
|
|
||||||
// data format assertions
|
// data format assertions
|
||||||
row._id ||= randomID();
|
row._id ||= randomID();
|
||||||
|
row.timestamp = new Date().toISOString();
|
||||||
|
|
||||||
|
Logger.debug(`Adding row:`, row);
|
||||||
this.#rows[userID][table].push(row);
|
this.#rows[userID][table].push(row);
|
||||||
this.render({ userUpdated: userID });
|
if (rerender) {
|
||||||
|
this.render({ userUpdated: userID });
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
static createRows(table, userID, rows, { rerender = true } = {}) {
|
||||||
|
if (!this.#tables[table]) { return };
|
||||||
|
this.#rows[userID] ??= {};
|
||||||
|
this.#rows[userID][table] ??= [];
|
||||||
|
|
||||||
|
// data format assertions
|
||||||
|
for (const row of rows) {
|
||||||
|
this.createRow( table, userID, row, { rerender: false } );
|
||||||
|
};
|
||||||
|
|
||||||
|
if (rerender) {
|
||||||
|
this.render({ userUpdated: userID });
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
static getRows(tableID, userIDs, privacy = `none`) {
|
static getRows(tableID, userIDs, privacy = `none`) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue