[WEB-2001] fix: Issue local cache fixes (#5703)
* Fix sync of local updates * Escape single quotes!! * Fix last updated time query * Move console.logs out * Fix issue title not rendering line breaks when disabled * Add a todo * Fix build errors * Disable local
This commit is contained in:
parent
6e0ece496a
commit
f3340749e8
11 changed files with 48 additions and 42 deletions
|
|
@ -15,7 +15,7 @@ import { loadWorkSpaceData } from "./utils/load-workspace";
|
|||
import { issueFilterCountQueryConstructor, issueFilterQueryConstructor } from "./utils/query-constructor";
|
||||
import { runQuery } from "./utils/query-executor";
|
||||
import { createTables } from "./utils/tables";
|
||||
import { getGroupedIssueResults, getSubGroupedIssueResults } from "./utils/utils";
|
||||
import { logError, getGroupedIssueResults, getSubGroupedIssueResults, logInfo, log } from "./utils/utils";
|
||||
|
||||
declare module "@sqlite.org/sqlite-wasm" {
|
||||
export function sqlite3Worker1Promiser(...args: any): any;
|
||||
|
|
@ -24,9 +24,6 @@ declare module "@sqlite.org/sqlite-wasm" {
|
|||
const DB_VERSION = 1;
|
||||
const PAGE_SIZE = 1000;
|
||||
const BATCH_SIZE = 200;
|
||||
const log = console.log;
|
||||
const error = console.error;
|
||||
const info = console.info;
|
||||
|
||||
type TProjectStatus = {
|
||||
issues: { status: undefined | "loading" | "ready" | "error" | "syncing"; sync: Promise<void> | undefined };
|
||||
|
|
@ -72,7 +69,7 @@ export class Storage {
|
|||
await this._initialize(workspaceSlug);
|
||||
return true;
|
||||
} catch (err) {
|
||||
error(err);
|
||||
logError(err);
|
||||
this.status = "error";
|
||||
return false;
|
||||
}
|
||||
|
|
@ -92,7 +89,7 @@ export class Storage {
|
|||
return false;
|
||||
}
|
||||
|
||||
info("Loading and initializing SQLite3 module...");
|
||||
logInfo("Loading and initializing SQLite3 module...");
|
||||
|
||||
this.workspaceSlug = workspaceSlug;
|
||||
this.dbName = workspaceSlug;
|
||||
|
|
@ -141,7 +138,7 @@ export class Storage {
|
|||
|
||||
await this.setOption("DB_VERSION", DB_VERSION.toString());
|
||||
} catch (err) {
|
||||
error(err);
|
||||
logError(err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
|
@ -179,15 +176,16 @@ export class Storage {
|
|||
this.setSync(projectId, sync);
|
||||
await sync;
|
||||
} catch (e) {
|
||||
logError(e);
|
||||
this.setStatus(projectId, "error");
|
||||
}
|
||||
};
|
||||
|
||||
_syncIssues = async (projectId: string) => {
|
||||
console.log("### Sync started");
|
||||
log("### Sync started");
|
||||
let status = this.getStatus(projectId);
|
||||
if (status === "loading" || status === "syncing") {
|
||||
info(`Project ${projectId} is already loading or syncing`);
|
||||
logInfo(`Project ${projectId} is already loading or syncing`);
|
||||
return;
|
||||
}
|
||||
const syncPromise = this.getSync(projectId);
|
||||
|
|
@ -235,7 +233,7 @@ export class Storage {
|
|||
if (syncedAt) {
|
||||
await syncDeletesToLocal(this.workspaceSlug, projectId, { updated_at__gt: syncedAt });
|
||||
}
|
||||
console.log("### Time taken to add issues", performance.now() - start);
|
||||
log("### Time taken to add issues", performance.now() - start);
|
||||
|
||||
if (status === "loading") {
|
||||
await createIndexes();
|
||||
|
|
@ -252,7 +250,7 @@ export class Storage {
|
|||
|
||||
getLastUpdatedIssue = async (projectId: string) => {
|
||||
const lastUpdatedIssue = await runQuery(
|
||||
`select id, name, updated_at , sequence_id from issues where project_id='${projectId}' order by datetime(updated_at) desc limit 1`
|
||||
`select id, name, updated_at , sequence_id from issues WHERE project_id='${projectId}' AND is_local_update IS NULL order by datetime(updated_at) desc limit 1 `
|
||||
);
|
||||
|
||||
if (lastUpdatedIssue.length) {
|
||||
|
|
@ -270,7 +268,7 @@ export class Storage {
|
|||
};
|
||||
|
||||
getIssues = async (workspaceSlug: string, projectId: string, queries: any, config: any) => {
|
||||
console.log("#### Queries", queries);
|
||||
log("#### Queries", queries);
|
||||
|
||||
const currentProjectStatus = this.getStatus(projectId);
|
||||
if (
|
||||
|
|
@ -280,7 +278,7 @@ export class Storage {
|
|||
currentProjectStatus === "error" ||
|
||||
!rootStore.user.localDBEnabled
|
||||
) {
|
||||
info(`Project ${projectId} is loading, falling back to server`);
|
||||
logInfo(`Project ${projectId} is loading, falling back to server`);
|
||||
const issueService = new IssueService();
|
||||
return await issueService.getIssuesFromServer(workspaceSlug, projectId, queries);
|
||||
}
|
||||
|
|
@ -307,7 +305,7 @@ export class Storage {
|
|||
const parsingStart = performance.now();
|
||||
let issueResults = issuesRaw.map((issue: any) => formatLocalIssue(issue));
|
||||
|
||||
console.log("#### Issue Results", issueResults.length);
|
||||
log("#### Issue Results", issueResults.length);
|
||||
|
||||
const parsingEnd = performance.now();
|
||||
|
||||
|
|
@ -326,7 +324,7 @@ export class Storage {
|
|||
Parsing: parsingEnd - parsingStart,
|
||||
Grouping: groupingEnd - grouping,
|
||||
};
|
||||
console.log(issueResults);
|
||||
log(issueResults);
|
||||
console.table(times);
|
||||
|
||||
const total_pages = Math.ceil(total_count / Number(pageSize));
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ export const deleteIssueFromLocal = async (issue_id: any) => {
|
|||
persistence.db.exec(deleteMetaQuery);
|
||||
persistence.db.exec("COMMIT;");
|
||||
};
|
||||
|
||||
export const updateIssue = async (issue: TIssue) => {
|
||||
// @todo: Update deletes the issue description from local. Implement a separate update.
|
||||
export const updateIssue = async (issue: TIssue & { is_local_update: number }) => {
|
||||
if (document.hidden || !rootStore.user.localDBEnabled) return;
|
||||
|
||||
const issue_id = issue.id;
|
||||
|
|
@ -82,10 +82,10 @@ const stageIssueInserts = (issue: any) => {
|
|||
return "";
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
return `'${JSON.stringify(value)}'`;
|
||||
return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return `'${value}'`;
|
||||
return `'${value.replace(/'/g, "''")}'`;
|
||||
}
|
||||
return value;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
singleFilterConstructor,
|
||||
translateQueryParams,
|
||||
} from "./query.utils";
|
||||
import { log } from "./utils";
|
||||
export const SPECIAL_ORDER_BY = {
|
||||
labels__name: "labels",
|
||||
"-labels__name": "labels",
|
||||
|
|
@ -47,7 +48,7 @@ export const issueFilterQueryConstructor = (workspaceSlug: string, projectId: st
|
|||
|
||||
`;
|
||||
|
||||
console.log("###", sql);
|
||||
log("###", sql);
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
|
@ -63,7 +64,7 @@ export const issueFilterQueryConstructor = (workspaceSlug: string, projectId: st
|
|||
WHERE rank <= ${per_page}
|
||||
`;
|
||||
|
||||
console.log("###", sql);
|
||||
log("###", sql);
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
|
@ -119,7 +120,7 @@ export const issueFilterQueryConstructor = (workspaceSlug: string, projectId: st
|
|||
`;
|
||||
sql += ` group by i.id ${orderByString} LIMIT ${pageSize} OFFSET ${offset * 1 + page * pageSize};`;
|
||||
|
||||
console.log("######$$$", sql);
|
||||
log("######$$$", sql);
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +149,7 @@ export const issueFilterQueryConstructor = (workspaceSlug: string, projectId: st
|
|||
// Add offset and paging to query
|
||||
sql += ` LIMIT ${pageSize} OFFSET ${offset * 1 + page * pageSize};`;
|
||||
|
||||
console.log("$$$", sql);
|
||||
log("$$$", sql);
|
||||
return sql;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export const issueSchema: Schema = {
|
|||
assignee_ids: "TEXT",
|
||||
module_ids: "TEXT",
|
||||
description_html: "TEXT",
|
||||
is_local_update: "INTEGER",
|
||||
};
|
||||
|
||||
export const issueMetaSchema: Schema = {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
memberSchema,
|
||||
optionsSchema,
|
||||
} from "./schemas";
|
||||
import { log } from "./utils";
|
||||
|
||||
const createTableSQLfromSchema = (tableName: string, schema: Schema) => {
|
||||
let sql = `CREATE TABLE IF NOT EXISTS ${tableName} (`;
|
||||
|
|
@ -18,7 +19,7 @@ const createTableSQLfromSchema = (tableName: string, schema: Schema) => {
|
|||
.map((key) => `'${key}' ${schema[key]}`)
|
||||
.join(", ");
|
||||
sql += `);`;
|
||||
console.log("#####", sql);
|
||||
log("#####", sql);
|
||||
return sql;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@ import { TIssue } from "@plane/types";
|
|||
import { rootStore } from "@/lib/store-context";
|
||||
import { updateIssue } from "./load-issues";
|
||||
|
||||
export const log = console.log;
|
||||
|
||||
// export const log = () => {};
|
||||
export const log = (...args: any) => {
|
||||
if ((window as any).DEBUG) {
|
||||
console.log(...args);
|
||||
}
|
||||
};
|
||||
export const logError = console.error;
|
||||
export const logInfo = console.info;
|
||||
|
||||
export const updatePersistentLayer = async (issueIds: string | string[]) => {
|
||||
if (typeof issueIds === "string") {
|
||||
|
|
@ -44,7 +48,7 @@ export const updatePersistentLayer = async (issueIds: string | string[]) => {
|
|||
"module_ids",
|
||||
"type_id",
|
||||
]);
|
||||
updateIssue(issuePartial);
|
||||
updateIssue({ ...issuePartial, is_local_update: 1 });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue