Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisation: edit operation takes 4.5s in large sheets #649

Merged
merged 9 commits into from
Dec 17, 2024
3 changes: 3 additions & 0 deletions packages/core/src/events/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { jfrefreshgrid } from "../modules/refresh";
import { setRowHeight } from "../api";
import { CFSplitRange } from "../modules";
import clipboard from "../modules/clipboard";
import { setFormulaCellInfo } from "../modules/formulaHelper";

function postPasteCut(
ctx: Context,
Expand All @@ -32,6 +33,7 @@ function postPasteCut(
// clearTimeout(refreshCanvasTimeOut);
for (let r = source.range.row[0]; r <= source.range.row[1]; r += 1) {
for (let c = source.range.column[0]; c <= source.range.column[1]; c += 1) {
setFormulaCellInfo(ctx, { r, c, id: source.sheetId });
if (`${r}_${c}_${source.sheetId}` in execF_rc) {
continue;
}
Expand All @@ -43,6 +45,7 @@ function postPasteCut(

for (let r = target.range.row[0]; r <= target.range.row[1]; r += 1) {
for (let c = target.range.column[0]; c <= target.range.column[1]; c += 1) {
setFormulaCellInfo(ctx, { r, c, id: source.sheetId });
if (`${r}_${c}_${target.sheetId}` in execF_rc) {
continue;
}
Expand Down
42 changes: 21 additions & 21 deletions packages/core/src/modules/ConditionFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ export function setConditionRules(
const rangeArr = getRangeByTxt(ctx, v);
// 判断条件值是不是选区
if (rangeArr.length > 1) {
const r1 = rangeArr[0].row[0];
const r2 = rangeArr[0].row[1];
const c1 = rangeArr[0].column[0];
const c2 = rangeArr[0].column[1];
const r1 = rangeArr[0]?.row[0];
const r2 = rangeArr[0]?.row[1];
const c1 = rangeArr[0]?.column[0];
const c2 = rangeArr[0]?.column[1];
if (r1 === r2 && c1 === c2) {
const d = getFlowdata(ctx);
if (!d) return;
if (!d || _.isNil(r1) || _.isNil(c1)) return;
v = getCellValue(r1, c1, d);
conditionRange.push({
row: rangeArr[0].row,
column: rangeArr[0].column,
row: rangeArr?.[0]?.row,
column: rangeArr?.[0]?.column,
});
conditionValue.push(v);
} else {
Expand All @@ -97,17 +97,17 @@ export function setConditionRules(
return;
}
if (rangeArr1.length === 1) {
const r1 = rangeArr1[0].row[0];
const r2 = rangeArr1[0].row[1];
const c1 = rangeArr1[0].column[0];
const c2 = rangeArr1[0].column[1];
const r1 = rangeArr1[0]?.row[0];
const r2 = rangeArr1[0]?.row[1];
const c1 = rangeArr1[0]?.column[0];
const c2 = rangeArr1[0]?.column[1];
if (r1 === r2 && c1 === c2) {
const d = getFlowdata(ctx);
if (!d) return;
if (!d || _.isNil(r1) || _.isNil(c1)) return;
v1 = getCellValue(r1, c1, d);
conditionRange.push({
row: rangeArr1[0].row,
column: rangeArr1[0].column,
row: rangeArr1?.[0]?.row,
column: rangeArr1?.[0]?.column,
});
conditionValue.push(v1);
} else {
Expand All @@ -127,17 +127,17 @@ export function setConditionRules(
return;
}
if (rangeArr2.length === 1) {
const r1 = rangeArr2[0].row[0];
const r2 = rangeArr2[0].row[1];
const c1 = rangeArr2[0].column[0];
const c2 = rangeArr2[0].column[1];
const r1 = rangeArr2[0]?.row[0];
const r2 = rangeArr2[0]?.row[1];
const c1 = rangeArr2[0]?.column[0];
const c2 = rangeArr2[0]?.column[1];
if (r1 === r2 && c1 === c2) {
const d = getFlowdata(ctx);
if (!d) return;
if (!d || _.isNil(r1) || _.isNil(c1)) return;
v2 = getCellValue(r1, c1, d);
conditionRange.push({
row: rangeArr2[0].row,
column: rangeArr2[0].column,
row: rangeArr2?.[0]?.row,
column: rangeArr2?.[0]?.column,
});
} else {
ctx.warnDialog = conditionformat.onlySingleCell;
Expand Down
36 changes: 19 additions & 17 deletions packages/core/src/modules/cell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import _ from "lodash";
import { Context, getFlowdata } from "../context";
import { Cell, CellMatrix, Range, Selection, SingleRange } from "../types";
import {
Cell,
CellMatrix,
FormulaDependency,
Range,
Selection,
SingleRange,
} from "../types";
import { getSheetIndex, indexToColumnChar, rgbToHex } from "../utils";
import { checkCF, getComputeMap } from "./ConditionFormat";
import { getFailureText, validateCellData } from "./dataVerification";
Expand All @@ -12,6 +19,7 @@ import {
functionHTMLGenerate,
getcellrange,
iscelldata,
isFormula,
} from "./formula";
import {
attrToCssName,
Expand All @@ -21,6 +29,7 @@ import {
} from "./inline-string";
import { isRealNull, isRealNum, valueIsError } from "./validation";
import { getCellTextInfo } from "./text";
import { setFormulaCellInfo } from "./formulaHelper";

// TODO put these in context ref
// let rangestart = false;
Expand Down Expand Up @@ -810,11 +819,11 @@ export function updateCell(
curv.ct.fa !== "@" &&
!isRealNull(value)
) {
delete curv.m; // 更新时间m处理 , 会实际删除单元格数据的参数(flowdata时已删除)
delete curv.m; // Update time m processing will actually delete the parameters of the cell data (the flowdata has been deleted)
if (curv.f) {
// 如果原来是公式,而更新的数据不是公式,则把公式删除
// If it turns out to be a formula but the updated data is not a formula, delete the formula.
delete curv.f;
delete curv.spl; // 删除单元格的sparklines的配置串
delete curv.spl; // Delete the configuration string of sparklines of the cell
}
}
}
Expand All @@ -828,7 +837,7 @@ export function updateCell(

if (_.isPlainObject(curv)) {
if (!isCurInline) {
if (_.isString(value) && value.slice(0, 1) === "=" && value.length > 1) {
if (isFormula(value)) {
const v = execfunction(ctx, value, r, c, undefined, undefined, true);
isRunExecFunction = false;
curv = _.cloneDeep(d?.[r]?.[c] || {});
Expand All @@ -854,11 +863,7 @@ export function updateCell(
else if (_.isPlainObject(value)) {
const valueFunction = value.f;

if (
_.isString(valueFunction) &&
valueFunction.slice(0, 1) === "=" &&
valueFunction.length > 1
) {
if (isFormula(valueFunction)) {
const v = execfunction(
ctx,
valueFunction,
Expand Down Expand Up @@ -919,7 +924,7 @@ export function updateCell(
}
value = curv;
} else {
if (_.isString(value) && value.slice(0, 1) === "=" && value.length > 1) {
if (isFormula(value)) {
const v = execfunction(ctx, value, r, c, undefined, undefined, true);
isRunExecFunction = false;
value = {
Expand All @@ -944,11 +949,7 @@ export function updateCell(
else if (_.isPlainObject(value)) {
const valueFunction = value.f;

if (
_.isString(valueFunction) &&
valueFunction.slice(0, 1) === "=" &&
valueFunction.length > 1
) {
if (isFormula(valueFunction)) {
const v = execfunction(
ctx,
valueFunction,
Expand Down Expand Up @@ -1085,6 +1086,7 @@ export function updateCell(
});
}

setFormulaCellInfo(ctx, { r, c, id: ctx.currentSheetId });
ctx.formulaCache.execFunctionGlobalData = null;
}

Expand Down Expand Up @@ -1212,7 +1214,7 @@ export function getRangetxt(

// 把string A1:A2转为选区数组
export function getRangeByTxt(ctx: Context, txt: string) {
let range = [];
let range: (FormulaDependency | null)[] = [];
if (txt.indexOf(",") !== -1) {
const arr = txt.split(",");
for (let i = 0; i < arr.length; i += 1) {
Expand Down
25 changes: 15 additions & 10 deletions packages/core/src/modules/dataVerification.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from "lodash";
import {
colLocationByIndex,
Context,
Expand Down Expand Up @@ -39,9 +40,9 @@ export function dataRangeSelection(
ctx.luckysheetCellUpdate = [row_index, col_index];

const range = getRangeByTxt(ctx, rangT);
const r = range[0].row;
const c = range[0].column;

const r = range[0]?.row;
const c = range[0]?.column;
if (_.isNil(r) || _.isNil(c)) return;
const row_pre = rowLocationByIndex(r[0], ctx.visibledatarow)[0];
const row = rowLocationByIndex(r[1], ctx.visibledatarow)[1];
const col_pre = colLocationByIndex(c[0], ctx.visibledatacolumn)[0];
Expand Down Expand Up @@ -69,9 +70,12 @@ export function getDropdownList(ctx: Context, txt: string) {
const list: (string | number | boolean)[] = [];
if (iscelldata(txt)) {
const range = getcellrange(ctx, txt);
const index = getSheetIndex(ctx, range.sheetId) as number;
const index = getSheetIndex(
ctx,
range?.sheetId || ctx.currentSheetId
) as number;
const d = ctx.luckysheetfile[index].data;
if (!d) return [];
if (!d || !range) return [];
for (let r = range.row[0]; r <= range.row[1]; r += 1) {
for (let c = range.column[0]; c <= range.column[1]; c += 1) {
if (!d[r]) {
Expand Down Expand Up @@ -854,12 +858,13 @@ export function confirmMessage(
ctx.warnDialog = generalDialog.noSeletionError;
return false;
}
let str = range[range.length - 1].row[0];
let edr = range[range.length - 1].row[1];
let stc = range[range.length - 1].column[0];
let edc = range[range.length - 1].column[1];
let str = range[range.length - 1]?.row[0];
let edr = range[range.length - 1]?.row[1];
let stc = range[range.length - 1]?.column[0];
let edc = range[range.length - 1]?.column[1];
const d = getFlowdata(ctx);
if (!d) return false;
if (!d || _.isNil(str) || _.isNil(edr) || _.isNil(stc) || _.isNil(edc))
return false;
if (str < 0) {
str = 0;
}
Expand Down
Loading
Loading