!1344 优化:如果用户开启了自动PU,那么在保存序列化时不序列化历史记录(以此增加性能和减少内存使用)

pull/1344/MERGE
ChenX 4 years ago
parent c7f4309d5f
commit 2376678aa8

@ -76,7 +76,7 @@ test('构建盖子失败2', () =>
{ {
//因为修改RegionParse精度降低到2个小数点就没问题了 //因为修改RegionParse精度降低到2个小数点就没问题了
let d = let d =
{ "file": [1, "Board", 8, 2, 100, false, 1, 6, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 97.11678151856177, -50.86622139217798, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 97.11678151856177, -50.86622139217798, 0, 1], 0, 3, 633, 361.5, 18, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [361.5, 0], 0, [361.5, 633], 0, [0, 633], 0, true, 2, 3, 100, 10, 5, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [10, 0], 0, [10, 100], 0, [0, 100], 0, true, 0, 3, 0, 0, 0, 0, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 448.61678151856177, -63.86622139217798, 266.5, 1], 3, 100, 20, 2.001107831095416, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [20, 0], 0, [20, 100], 0, [0, 100], 0, true, 0, 3, 0, 0, 0, 0, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 438.61678151856177, -50.86622139217798, 266.49751214702076, 1], 3, 0, 0, 0, 0, 0, 9, 2, "左开门板", "主卧", "衣柜", "", "", "", 0, 0, "不排", 2, 0, "1.5", "1.5", "1.5", "1.5", "", "", "", 4, "不排", "不排", "不排", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 1, true], "basePt": { "x": 97.11678151856177, "y": -68.86622139217798, "z": 0; }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; }; { "file": [1, "Board", 8, 2, 100, false, 1, 6, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 97.11678151856177, -50.86622139217798, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 97.11678151856177, -50.86622139217798, 0, 1], 0, 3, 633, 361.5, 18, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [361.5, 0], 0, [361.5, 633], 0, [0, 633], 0, true, 2, 3, 100, 10, 5, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [10, 0], 0, [10, 100], 0, [0, 100], 0, true, 0, 3, 0, 0, 0, 0, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 448.61678151856177, -63.86622139217798, 266.5, 1], 3, 100, 20, 2.001107831095416, true, "Polyline", 8, 2, 0, false, 0, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 4, [0, 0], 0, [20, 0], 0, [20, 100], 0, [0, 100], 0, true, 0, 3, 0, 0, 0, 0, 0, [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 438.61678151856177, -50.86622139217798, 266.49751214702076, 1], 3, 0, 0, 0, 0, 0, 9, 2, "左开门板", "主卧", "衣柜", "", "", "", 0, 0, "不排", 2, 0, "1.5", "1.5", "1.5", "1.5", "", "", "", 4, "不排", "不排", "不排", "不排", true, true, 0, 0, 0, 0, 0, 0, 0, 1, true], "basePt": { "x": 97.11678151856177, "y": -68.86622139217798, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let brs = LoadBoardsFromFileData(d); let brs = LoadBoardsFromFileData(d);
for (let br of brs) for (let br of brs)

@ -60,14 +60,25 @@ export class Save implements Command
} }
let db = app.Database; let db = app.Database;
let f = db.FileWrite(); let f: CADFiler;
let vf = new CADFiler();
app.Viewer.CameraCtrl.WriteFile(vf);
let isError = false; let isError = false;
if (userConfig.autoClearHistory) if (userConfig.autoClearHistory)
{ {
//备份,清理
let hrBak = app.Database.hm.historyRecord;
let hrIndex = app.Database.hm.curIndex;
app.Database.hm.historyRecord = [];
app.Database.hm.curIndex = -1;
//拷贝db
f = db.FileWrite();
db = new Database().FileRead(f); db = new Database().FileRead(f);
//还原
app.Database.hm.historyRecord = hrBak;
app.Database.hm.curIndex = hrIndex;
try try
{ {
Purge(db); Purge(db);
@ -89,7 +100,11 @@ export class Save implements Command
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
} }
else
f = db.FileWrite();
let vf = new CADFiler();
app.Viewer.CameraCtrl.WriteFile(vf);
f.Write(vf.Data); f.Write(vf.Data);
f.Write(app.Editor.UCSMatrix.toArray()); f.Write(app.Editor.UCSMatrix.toArray());
@ -214,7 +229,7 @@ function UploadFileHistory(file: any)
let userName = localStorage.getItem(StoreageKeys.UserName); let userName = localStorage.getItem(StoreageKeys.UserName);
//记录历史记录 //记录历史记录
let hisStart = app.Database.hm.curIndex - 3;//前十个 let hisStart = app.Database.hm.curIndex - 3 + 1;//前n条历史记录
let hisIndex = app.Database.hm.curIndex; let hisIndex = app.Database.hm.curIndex;
//修正当前开始位置 //修正当前开始位置
if (hisStart < 0) if (hisStart < 0)
@ -222,7 +237,7 @@ function UploadFileHistory(file: any)
else else
hisIndex -= hisStart; hisIndex -= hisStart;
let hisEnd = Math.min(app.Database.hm.historyRecord.length, hisIndex + 3);//后10 let hisEnd = Math.min(app.Database.hm.historyRecord.length, app.Database.hm.curIndex + 3 + 1);//后n条历史记录
let hisf = new CADFiler(); let hisf = new CADFiler();
//参考HistoryManager的序列化 //参考HistoryManager的序列化

@ -1,18 +1,30 @@
import { Purge } from "../Add-on/Purge";
import { app } from "../ApplicationServices/Application"; import { app } from "../ApplicationServices/Application";
import { Database } from "../DatabaseServices/Database";
import { arrayRemoveIf } from "../Common/ArrayExt";
import { IndexedDbStore, StoreName } from "../IndexedDb/IndexedDbStore";
import { Log } from "../Common/Log"; import { Log } from "../Common/Log";
import { StoreageKeys } from "../Common/StoreageKeys"; import { StoreageKeys } from "../Common/StoreageKeys";
import { TopPanelStore } from "../UI/Store/TopPanelStore"; import { CADFiler } from "../DatabaseServices/CADFiler";
import { userConfig } from "./UserConfig"; import { Database } from "../DatabaseServices/Database";
import { FileServer } from "../DatabaseServices/FileServer"; import { FileServer } from "../DatabaseServices/FileServer";
import { IndexedDbStore, StoreName } from "../IndexedDb/IndexedDbStore";
import { TopPanelStore } from "../UI/Store/TopPanelStore";
import { CommandState } from "./CommandState";
import { TempEditor } from "./TempEditor"; import { TempEditor } from "./TempEditor";
import { userConfig } from "./UserConfig";
/**
* TENET()
* ,2.
* 1..,,.()
* 2..,,.(,)
*
* :
* ()
*/
export class AutoSaveServer export class AutoSaveServer
{ {
//缓存过了 //缓存过了
isCached = false; isCached = false;
private lastTime = 0;
private timeId: NodeJS.Timeout; private timeId: NodeJS.Timeout;
constructor() constructor()
{ {
@ -22,39 +34,61 @@ export class AutoSaveServer
this.isCached = false; this.isCached = false;
}); });
} }
Start() Start()
{ {
this.Stop(); this.Stop();
this.timeId = setInterval(() => this.Do(), userConfig.autoSaveConfig.time * 60 * 1000);
}
Stop()
{
if (this.timeId)
{
clearInterval(this.timeId);
this.timeId = null;
}
}
Do()
{
let now = Date.now();
if (userConfig.autoSaveConfig.enable
&& now - this.lastTime > userConfig.autoSaveConfig.time * 60 * 1000)
{
this.SaveFile();
this.lastTime = now;
}
}
private SaveFile()
{
const topStore = TopPanelStore.GetInstance() as TopPanelStore; const topStore = TopPanelStore.GetInstance() as TopPanelStore;
this.timeId = setInterval(async () => if (app.Saved || this.isCached)
{ {
if (app.Saved || !topStore.editoring || this.isCached || TempEditor.EditorIng) return; // console.log("文件已经被保存,不需要自动保存!");
return;
}
if (!topStore.editoring || TempEditor.EditorIng || CommandState.CommandIng)
{
console.log("文件正在编辑中稍后重试!");
// setTimeout(() => this.SaveFile(), 1000);//
return;
};
let f = AppDbWriteToFile();
let f = app.Database.FileWrite();
if (false) if (false)
{ {
let newDB = new Database().FileRead(f); let newDB = new Database().FileRead(f);
newDB.hm.Clear(); Purge(newDB);
arrayRemoveIf(newDB.ModelSpace.Entitys, e => e.IsErase);
arrayRemoveIf(newDB.TemplateTable.Objects, e => e.IsErase);
arrayRemoveIf(newDB.GroupTable.Objects, g =>
{
return g.Entitys.length === 0 || g.Entitys.every(e => !e || e.IsErase);
});
f = newDB.FileWrite(); f = newDB.FileWrite();
} }
//异步不等待 //异步不等待
this.SavaData(f.Data); this.SavaData(f.Data);
}, userConfig.autoSaveConfig.time * 60 * 1000);
}
Stop()
{
if (this.timeId)
{
clearInterval(this.timeId);
this.timeId = null;
}
} }
async SavaData(data: any[]) async SavaData(data: any[])
{ {
const indexDbStore = await IndexedDbStore.CADStore(); const indexDbStore = await IndexedDbStore.CADStore();
@ -63,13 +97,47 @@ export class AutoSaveServer
if (uid) if (uid)
{ {
indexDbStore.Put(StoreName.FileCache, uid, { time: new Date().toLocaleString(), data, fid: server.m_CurFileId }); indexDbStore.Put(StoreName.FileCache, uid, { time: new Date().toLocaleString(), data, fid: server.m_CurFileId });
Log("文件缓存成功!"); Log("文件自动备份成功!");
} }
this.isCached = true; this.isCached = true;
} }
async Clear()
public async Clear()
{ {
const store = await IndexedDbStore.CADStore(); const store = await IndexedDbStore.CADStore();
store.Delete(StoreName.FileCache, localStorage.getItem(StoreageKeys.Uid)); store.Delete(StoreName.FileCache, localStorage.getItem(StoreageKeys.Uid));
} }
} }
/**
* ,
* @returns
*/
function AppDbWriteToFile(): CADFiler
{
const SaveRecordCount = 3; //前N条和后N条历史记录
let hisStart = app.Database.hm.curIndex - SaveRecordCount + 1; //前n条历史记录
let hisIndex = app.Database.hm.curIndex;
//修正当前开始位置
if (hisStart < 0)
hisStart = 0;
else
hisIndex -= hisStart;
//结束为止
let hisEnd = Math.min(app.Database.hm.historyRecord.length, app.Database.hm.curIndex + SaveRecordCount + 1); //后n条历史记录
//备份,清理
let hrBak = app.Database.hm.historyRecord;
let hrIndex = app.Database.hm.curIndex;
app.Database.hm.curIndex = hisIndex;
app.Database.hm.historyRecord = hrBak.slice(hisStart, hisEnd);
let f = app.Database.FileWrite();
app.Database.hm.historyRecord = hrBak;
app.Database.hm.curIndex = hrIndex;
return f;
}

@ -157,6 +157,8 @@ class CommandMachine
app.Database.hm.Undo(); app.Database.hm.Undo();
} }
app.AutoSaveServer.Do();//触发自动保存,在这里触发自动保存,保证历史记录已经被写入(是完整的)
app.Viewer.GripScene.visible = true; app.Viewer.GripScene.visible = true;
app.Viewer.GripScene.UpdateAll(); app.Viewer.GripScene.UpdateAll();
app.Editor.UpdateScreen(); app.Editor.UpdateScreen();

@ -94,7 +94,7 @@ export class SystemConfigPanel extends React.Component
uiOption={this.saveUiData} uiOption={this.saveUiData}
type={CheckObjectType.GT0Num} type={CheckObjectType.GT0Num}
/> />
<span style={{ marginLeft: 10 }}>mins</span> <span style={{ marginLeft: 10 }}></span>
</Label> </Label>
</Tooltip> </Tooltip>
<Tooltip content="对保存的图纸进行自动PU操作,这样会使图纸更小!(该操作只对上传的文件生效,本地文件仍然未PU!)"> <Tooltip content="对保存的图纸进行自动PU操作,这样会使图纸更小!(该操作只对上传的文件生效,本地文件仍然未PU!)">

Loading…
Cancel
Save