[WEB-2001] feat: Fix local cache issues v2 (#5712)

* - Handle single quotes in load workspace queries
- Add IS null where condition in query utils

* Fix description_html being lost

* Change secondary order to sequence_id

* Fix update persistence layer
This commit is contained in:
Satish Gandham 2024-09-27 13:19:38 +05:30 committed by GitHub
parent ade03e9f8f
commit 8aa32d410c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 13 deletions

View file

@ -10,6 +10,7 @@ export const createIssueIndexes = async () => {
"project_id", "project_id",
"created_by", "created_by",
"cycle_id", "cycle_id",
"sequence_id",
]; ];
const promises: Promise<any>[] = []; const promises: Promise<any>[] = [];

View file

@ -27,10 +27,10 @@ const stageInserts = (table: string, schema: Schema, data: any) => {
return ""; return "";
} }
if (typeof value === "object") { if (typeof value === "object") {
return `'${JSON.stringify(value)}'`; return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
} }
if (typeof value === "string") { if (typeof value === "string") {
return `'${value}'`; return `'${value.replace(/'/g, "''")}'`;
} }
return value; return value;
}) })

View file

@ -47,9 +47,9 @@ export const getOrderByFragment = (order_by: string, table = "") => {
if (!order_by) return orderByString; if (!order_by) return orderByString;
if (order_by.startsWith("-")) { 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 { } 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; return orderByString;
}; };
@ -130,7 +130,7 @@ export const getFilteredRowsForGrouping = (projectId: string, queries: any) => {
let sql = ""; let sql = "";
if (!joinsRequired) { 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) {
if (group_by === "target_date") { if (group_by === "target_date") {
sql += `, date(i.${group_by}) as group_id`; sql += `, date(i.${group_by}) as group_id`;
@ -153,7 +153,7 @@ export const getFilteredRowsForGrouping = (projectId: string, queries: any) => {
} }
sql = `WITH fi AS (`; 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 (group_by) {
if (ARRAY_FIELDS.includes(group_by)) { if (ARRAY_FIELDS.includes(group_by)) {
sql += `, ${group_by}.value as group_id sql += `, ${group_by}.value as group_id
@ -238,7 +238,10 @@ export const singleFilterConstructor = (queries: any) => {
keys.forEach((key) => { keys.forEach((key) => {
const value = filters[key] ? filters[key].split(",") : ""; const value = filters[key] ? filters[key].split(",") : "";
if (!value) return; if (!value) {
sql += ` AND ${key} IS NULL`;
return;
}
if (!ARRAY_FIELDS.includes(key)) { if (!ARRAY_FIELDS.includes(key)) {
sql += ` AND ${key} in ('${value.join("','")}') sql += ` AND ${key} in ('${value.join("','")}')
`; `;
@ -249,10 +252,6 @@ export const singleFilterConstructor = (queries: any) => {
return sql; 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) => { const createDateFilter = (key: string, q: string) => {
let sql = " "; let sql = " ";
// get todays date in YYYY-MM-DD format // get todays date in YYYY-MM-DD format

View file

@ -1,6 +1,7 @@
import pick from "lodash/pick"; import pick from "lodash/pick";
import { TIssue } from "@plane/types"; import { TIssue } from "@plane/types";
import { rootStore } from "@/lib/store-context"; import { rootStore } from "@/lib/store-context";
import { persistence } from "../storage.sqlite";
import { updateIssue } from "./load-issues"; import { updateIssue } from "./load-issues";
export const log = (...args: any) => { export const log = (...args: any) => {
@ -15,11 +16,13 @@ export const updatePersistentLayer = async (issueIds: string | string[]) => {
if (typeof issueIds === "string") { if (typeof issueIds === "string") {
issueIds = [issueIds]; issueIds = [issueIds];
} }
issueIds.forEach((issueId) => { issueIds.forEach(async (issueId) => {
const dbIssue = await persistence.getIssue(issueId);
const issue = rootStore.issue.issues.getIssueById(issueId); const issue = rootStore.issue.issues.getIssueById(issueId);
if (issue) { 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", "id",
"name", "name",
"state_id", "state_id",
@ -47,6 +50,7 @@ export const updatePersistentLayer = async (issueIds: string | string[]) => {
"label_ids", "label_ids",
"module_ids", "module_ids",
"type_id", "type_id",
"description_html",
]); ]);
updateIssue({ ...issuePartial, is_local_update: 1 }); updateIssue({ ...issuePartial, is_local_update: 1 });
} }