Merge branch 'fix-local-cache-issues' of gurusainath:makeplane/plane into fix-local-cache-issues

This commit is contained in:
gurusainath
2024-10-04 16:30:25 +05:30
6 changed files with 26 additions and 18 deletions

View File

@@ -148,7 +148,7 @@ export class Storage {
};
syncWorkspace = async () => {
if (document.hidden || !rootStore.user.localDBEnabled) return; // return if the window gets hidden
if (document.hidden || !rootStore.user.localDBEnabled || !this.db) return; // return if the window gets hidden
await Sentry.startSpan({ name: "LOAD_WS", attributes: { slug: this.workspaceSlug } }, async () => {
await loadWorkSpaceData(this.workspaceSlug);
});
@@ -173,7 +173,7 @@ export class Storage {
};
syncIssues = async (projectId: string) => {
if (document.hidden || !rootStore.user.localDBEnabled) return false; // return if the window gets hidden
if (document.hidden || !rootStore.user.localDBEnabled || !this.db) return false; // return if the window gets hidden
try {
const sync = Sentry.startSpan({ name: `SYNC_ISSUES` }, () => this._syncIssues(projectId));
@@ -191,7 +191,7 @@ export class Storage {
log("### Sync started");
let status = this.getStatus(projectId);
if (status === "loading" || status === "syncing") {
logInfo(`Project ${projectId} is already loading or syncing`);
log(`Project ${projectId} is already loading or syncing`);
return;
}
const syncPromise = this.getSync(projectId);
@@ -290,7 +290,7 @@ export class Storage {
!rootStore.user.localDBEnabled
) {
if (rootStore.user.localDBEnabled) {
logInfo(`Project ${projectId} is loading, falling back to server`);
log(`Project ${projectId} is loading, falling back to server`);
}
const issueService = new IssueService();
return await issueService.getIssuesFromServer(workspaceSlug, projectId, queries);

View File

@@ -8,7 +8,7 @@ import { issueSchema } from "./schemas";
export const PROJECT_OFFLINE_STATUS: Record<string, boolean> = {};
export const addIssue = async (issue: any) => {
if (document.hidden || !rootStore.user.localDBEnabled) return;
if (document.hidden || !rootStore.user.localDBEnabled || !persistence.db) return;
persistence.db.exec("BEGIN TRANSACTION;");
stageIssueInserts(issue);
@@ -16,7 +16,7 @@ export const addIssue = async (issue: any) => {
};
export const addIssuesBulk = async (issues: any, batchSize = 100) => {
if (!rootStore.user.localDBEnabled) return;
if (!rootStore.user.localDBEnabled || !persistence.db) return;
for (let i = 0; i < issues.length; i += batchSize) {
const batch = issues.slice(i, i + batchSize);
@@ -32,7 +32,7 @@ export const addIssuesBulk = async (issues: any, batchSize = 100) => {
}
};
export const deleteIssueFromLocal = async (issue_id: any) => {
if (!rootStore.user.localDBEnabled) return;
if (!rootStore.user.localDBEnabled || !persistence.db) return;
const deleteQuery = `delete from issues where id='${issue_id}'`;
const deleteMetaQuery = `delete from issue_meta where issue_id='${issue_id}'`;
@@ -44,7 +44,7 @@ export const deleteIssueFromLocal = async (issue_id: any) => {
};
// @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;
if (document.hidden || !rootStore.user.localDBEnabled || !persistence.db) return;
const issue_id = issue.id;
// delete the issue and its meta data
@@ -53,7 +53,7 @@ export const updateIssue = async (issue: TIssue & { is_local_update: number }) =
};
export const syncDeletesToLocal = async (workspaceId: string, projectId: string, queries: any) => {
if (!rootStore.user.localDBEnabled) return;
if (!rootStore.user.localDBEnabled || !persistence.db) return;
const issueService = new IssueService();
const response = await issueService.getDeletedIssues(workspaceId, projectId, queries);

View File

@@ -1,9 +1,7 @@
// import { SQL } from "./sqlite";
import { persistence } from "../storage.sqlite";
export const runQuery = async (sql: string) => {
const data = await persistence.db.exec({
const data = await persistence.db?.exec({
sql,
rowMode: "object",
returnValue: "resultRows",

View File

@@ -4,8 +4,20 @@ import { issueSchema } from "./schemas";
import { wrapDateTime } from "./utils";
export const translateQueryParams = (queries: any) => {
const { group_by, sub_group_by, labels, assignees, state, cycle, module, priority, type, issue_type, ...otherProps } =
queries;
const {
group_by,
layout,
sub_group_by,
labels,
assignees,
state,
cycle,
module,
priority,
type,
issue_type,
...otherProps
} = queries;
const order_by = queries.order_by;
if (state) otherProps.state_id = state;
@@ -33,7 +45,7 @@ export const translateQueryParams = (queries: any) => {
}
// Fix invalid orderby when switching from spreadsheet layout
if ((group_by || sub_group_by) && Object.keys(SPECIAL_ORDER_BY).includes(order_by)) {
if (layout === "spreadsheet" && Object.keys(SPECIAL_ORDER_BY).includes(order_by)) {
otherProps.order_by = "sort_order";
}
// For each property value, replace None with empty string

View File

@@ -15,7 +15,7 @@ export const logError = (e: any) => {
e = parseSQLite3Error(e);
}
Sentry.captureException(e);
console.log(e);
console.error(e);
};
export const logInfo = console.info;

View File

@@ -20,8 +20,6 @@ const nextConfig = {
key: "Referrer-Policy",
value: "origin-when-cross-origin",
},
{ key: "Cross-Origin-Opener-Policy", value: "same-origin" },
{ key: "Cross-Origin-Embedder-Policy", value: "credentialless" },
],
},
];