π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-2001] feat: Fix local cache issues v2 (#5712)
Satish Gandham8aa32d410c31
diff --git a/web/core/local-db/utils/indexes.ts b/web/core/local-db/utils/indexes.tsindex aeff6992e9..214bacb44f 100644--- a/web/core/local-db/utils/indexes.ts+++ b/web/core/local-db/utils/indexes.ts@@ -10,6 +10,7 @@ export const createIssueIndexes = async () => {"project_id","created_by","cycle_id",+ "sequence_id",];const promises: Promise<any>[] = [];diff --git a/web/core/local-db/utils/load-workspace.ts b/web/core/local-db/utils/load-workspace.tsindex 36d2aabce9..87231161c6 100644--- a/web/core/local-db/utils/load-workspace.ts+++ b/web/core/local-db/utils/load-workspace.ts@@ -27,10 +27,10 @@ const stageInserts = (table: string, schema: Schema, data: 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;})diff --git a/web/core/local-db/utils/query.utils.ts b/web/core/local-db/utils/query.utils.tsindex e95174bc7f..ad012a30a9 100644--- a/web/core/local-db/utils/query.utils.ts+++ b/web/core/local-db/utils/query.utils.ts@@ -47,9 +47,9 @@ export const getOrderByFragment = (order_by: string, table = "") => {if (!order_by) return orderByString;if (order_by.startsWith("-")) {- orderByString += ` ORDER BY ${wrapDateTime(order_by.slice(1))} DESC NULLS LAST, datetime(${table}created_at) DESC`;+ orderByString += ` ORDER BY ${wrapDateTime(order_by.slice(1))} DESC NULLS LAST, ${table}sequence_id DESC`;} else {- orderByString += ` ORDER BY ${wrapDateTime(order_by)} ASC NULLS LAST, datetime(${table}created_at) DESC`;+ orderByString += ` ORDER BY ${wrapDateTime(order_by)} ASC NULLS LAST, ${table}sequence_id DESC`;}return orderByString;};@@ -130,7 +130,7 @@ export const getFilteredRowsForGrouping = (projectId: string, queries: any) => {let sql = "";if (!joinsRequired) {- sql = `WITH fi as (SELECT i.id,i.created_at ${issueTableFilterFields}`;+ sql = `WITH fi as (SELECT i.id,i.created_at, i.sequence_id ${issueTableFilterFields}`;if (group_by) {if (group_by === "target_date") {sql += `, date(i.${group_by}) as group_id`;@@ -153,7 +153,7 @@ export const getFilteredRowsForGrouping = (projectId: string, queries: any) => {}sql = `WITH fi AS (`;- sql += `SELECT i.id,i.created_at ${issueTableFilterFields} `;+ sql += `SELECT i.id,i.created_at,i.sequence_id ${issueTableFilterFields} `;if (group_by) {if (ARRAY_FIELDS.includes(group_by)) {sql += `, ${group_by}.value as group_id@@ -238,7 +238,10 @@ export const singleFilterConstructor = (queries: any) => {keys.forEach((key) => {const value = filters[key] ? filters[key].split(",") : "";- if (!value) return;+ if (!value) {+ sql += ` AND ${key} IS NULL`;+ return;+ }if (!ARRAY_FIELDS.includes(key)) {sql += ` AND ${key} in ('${value.join("','")}')`;@@ -249,10 +252,6 @@ export const singleFilterConstructor = (queries: any) => {return sql;};-// let q = '2_months;after;fromnow,1_months;after;fromnow,2024-09-01;after,2024-10-06;after,2_weeks;after;fromnow'--// ["2_months;after;fromnow", "1_months;after;fromnow", "2024-09-01;after", "2024-10-06;before", "2_weeks;after;fromnow"];-const createDateFilter = (key: string, q: string) => {let sql = " ";// get todays date in YYYY-MM-DD formatdiff --git a/web/core/local-db/utils/utils.ts b/web/core/local-db/utils/utils.tsindex 619ec9af8d..368a19e7fa 100644--- a/web/core/local-db/utils/utils.ts+++ b/web/core/local-db/utils/utils.ts@@ -1,6 +1,7 @@import pick from "lodash/pick";import { TIssue } from "@plane/types";import { rootStore } from "@/lib/store-context";+import { persistence } from "../storage.sqlite";import { updateIssue } from "./load-issues";export const log = (...args: any) => {@@ -15,11 +16,13 @@ export const updatePersistentLayer = async (issueIds: string | string[]) => {if (typeof issueIds === "string") {issueIds = [issueIds];}- issueIds.forEach((issueId) => {+ issueIds.forEach(async (issueId) => {+ const dbIssue = await persistence.getIssue(issueId);const issue = rootStore.issue.issues.getIssueById(issueId);if (issue) {- const issuePartial = pick(JSON.parse(JSON.stringify(issue)), [+ // JSON.parse(JSON.stringify(issue)) is used to remove the mobx observables+ const issuePartial = pick({ ...dbIssue, ...JSON.parse(JSON.stringify(issue)) }, ["id","name","state_id",@@ -47,6 +50,7 @@ export const updatePersistentLayer = async (issueIds: string | string[]) => {"label_ids","module_ids","type_id",+ "description_html",]);updateIssue({ ...issuePartial, is_local_update: 1 });}