perf: optimize full interface loading and refresh paths
This commit is contained in:
1 parent
649a0df832
commit
f317314a3c
57 files changed
+791
-136
No files matched your search
Vendored
+1
-1
@@ -18,5 +18,5 @@ async function startTestDashboard({stateDir,mailHistory=false,executionFactory})
|
||||
await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(0,'127.0.0.1',resolve);});
|
||||
return {server,store,workspace,orderRules,mail,orderExecution,async close(){await orderExecution?.stop();await mail?.stop();server.closeAllConnections();await new Promise(r=>server.close(r));workspace.close();orderRules.close();mailStore?.close();}};
|
||||
}
|
||||
async function login(page){await page.getByLabel('账号',{exact:true}).fill('admin');await page.getByLabel('密码',{exact:true}).fill('Test-password-123');await page.getByRole('button',{name:'登录',exact:true}).click();}
|
||||
async function login(page){await page.getByLabel('账号',{exact:true}).fill('admin');await page.getByLabel('密码',{exact:true}).fill('Test-password-123');await Promise.all([page.waitForResponse(response=>response.url().endsWith('/api/login')&&response.request().method()==='POST'),page.getByRole('button',{name:'登录',exact:true}).click()]);await page.locator('#logout').waitFor();}
|
||||
module.exports={startTestDashboard,login};
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
const crypto=require('node:crypto');
|
||||
const {DatabaseSync}=require('node:sqlite');
|
||||
const {RuleStore}=require('../../src/modules/order-rules/store.cjs');
|
||||
const {BpmVault}=require('../../src/platform/security/vault.cjs');
|
||||
function fixture(n,{status='pending',huizhou=false}={}){
|
||||
const db=new DatabaseSync(':memory:');db.exec('CREATE TABLE records(kind TEXT,id TEXT,payload BLOB,PRIMARY KEY(kind,id))');
|
||||
const vault=Object.assign(Object.create(BpmVault.prototype),{key:crypto.randomBytes(32)}),counts={all:{},get:{},decode:0};let now=new Date('2026-10-26T01:00:00Z');
|
||||
const store=Object.assign(Object.create(RuleStore.prototype),{db,vault,clock:()=>new Date(now),schedule:()=>({times:['11:00','17:00'],weekends:false}),calendar:()=>[],capabilities:{}});
|
||||
store.put('settings',{id:'main',version:1,enabled:false,processingEnabled:false,channelId:'',maxMessageBytes:20971520});
|
||||
for(const draft of require('../../src/modules/order-rules/catalog.cjs').seedRules())store.put('rules',{id:draft.id,draft,published:null});
|
||||
const rule={id:'bs-change',categoryId:'bs-change',name:'Synthetic',version:1,processNames:['Synthetic'],nodeNames:['Node'],scopes:[{processName:'Synthetic',nodeName:'Node'}],huizhouEnabled:huizhou,to:['fixture@example.invalid']};
|
||||
for(let i=0;i<n;i++){
|
||||
const row={connectionId:'a',source:'todo',portalSource:'v4',instanceId:String(i),taskId:String(i),revision:'1',processName:'Synthetic',processVersion:'1',nodeName:'Node',receivedAt:'2026-10-26T00:30:00Z',orderNo:String(i),title:'Synthetic '+i};
|
||||
store.put('orders',{id:'o'+i,categoryId:rule.categoryId,status,sample:row,event:row,ruleSnapshot:rule,createdAt:row.receivedAt,notifications:huizhou?{huizhou:{status:'pending',orderNos:['H'+i],issues:[]}}:undefined});
|
||||
store.put('execution-tasks',{id:'t'+i,orderId:'o'+i,connectionId:'a',status,step:'complete',categoryIds:[rule.categoryId],row,createdAt:row.receivedAt});
|
||||
}
|
||||
const all=store.all,get=store.get,decode=vault.decode;
|
||||
store.all=function(kind){counts.all[kind]=(counts.all[kind]||0)+1;return all.call(this,kind);};
|
||||
store.get=function(kind,id){counts.get[kind]=(counts.get[kind]||0)+1;return get.call(this,kind,id);};
|
||||
vault.decode=function(...args){counts.decode++;return decode.apply(this,args);};
|
||||
return {store,counts,context:{orderRules:store,workspace:{recordSources:()=>[{id:'a',owner:'alice'}],businessIssue:()=>null}},actor:{username:'alice',role:'operator'},reset(){counts.all={};counts.get={};counts.decode=0;},setNow(value){now=new Date(value);},close(){db.close();vault.key.fill(0);}};
|
||||
}
|
||||
module.exports={fixture};
|
||||
Vendored
+1
-1
@@ -2,5 +2,5 @@
|
||||
const fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
||||
const {Store}=require('../../src/modules/dashboard/store.cjs'),{WorkspaceStore}=require('../../src/modules/workspace/store.cjs'),{BpmScanStore}=require('../../src/modules/bpm/scan-store.cjs'),{BpmScanner}=require('../../src/modules/bpm/scanner.cjs'),{createDashboard}=require('../../src/app/dashboard.cjs'),{loadPlaywright,browserOptions}=require('../../src/platform/browser.cjs');
|
||||
async function setup(t){const dir=fs.mkdtempSync(path.join(os.tmpdir(),'record-nav-')),store=new Store(path.join(dir,'dashboard')),workspace=new WorkspaceStore(path.join(dir,'workspace')),scan=new BpmScanStore(path.join(dir,'scan')),password='Record-nav-test-123',actor={username:'admin',role:'admin'};store.bootstrap('admin',password);for(const role of ['viewer','operator'])store.addUser({username:role,password,role},'admin');const connection=workspace.createConnection({name:'隔离测试来源',owner:'admin'},actor,store.users());scan.saveConfig({enabled:false,intervalMinutes:9});scan.complete(scan.begin(connection.id,'admin'),connection.id,Array.from({length:105},(_,i)=>({taskId:String(i).padStart(3,'0'),serialNum:'TEST-'+String(i).padStart(3,'0'),source:'portal-v4',processName:'海外运营订单评审',activityName:'通知节点',subject:'订单样例 '+String(i).padStart(3,'0'),arrivalDay:'2026-10-20',arrivedAt:'2026-10-20T01:00:00Z'})),connection);for(let i=0;i<105;i++)store.recordJob({jobId:'job-'+String(i).padStart(3,'0'),status:'error',metadata:{order:'PDF-'+String(i).padStart(3,'0')},error:'隔离导出失败'});const scanner=new BpmScanner({store:scan,workspace,manager:{scanArrivals:async()=>[]},settings:()=>store.settings()}),server=createDashboard({store,workspace,scanner,outputDir:dir});await new Promise(r=>server.listen(0,'127.0.0.1',r));const browser=await loadPlaywright().chromium.launch(browserOptions()),base='http://127.0.0.1:'+server.address().port;
|
||||
t.after(async()=>{await browser.close();await scanner.stop();server.closeAllConnections();await new Promise(r=>server.close(r));scan.close();workspace.close();fs.rmSync(dir,{recursive:true,force:true});});return {store,workspace,scan,connection,browser,base,password,async page(route='#records',username='admin',clock=false){const page=await browser.newPage({viewport:{width:1280,height:900}});if(clock)await page.clock.install();await page.goto(base+'/'+route);await page.locator('#username').fill(username);await page.locator('#password').fill(password);await page.locator('#login-form button').click();return page;}};}
|
||||
t.after(async()=>{await browser.close();await scanner.stop();server.closeAllConnections();await new Promise(r=>server.close(r));scan.close();workspace.close();fs.rmSync(dir,{recursive:true,force:true});});return {store,workspace,scan,connection,browser,base,password,async page(route='#records',username='admin',clock=false){const page=await browser.newPage({viewport:{width:1280,height:900}});if(clock)await page.clock.install();await page.goto(base+'/'+route);await page.locator('#username').fill(username);await page.locator('#password').fill(password);await Promise.all([page.waitForResponse(response=>response.url().endsWith('/api/login')&&response.request().method()==='POST'),page.locator('#login-form button').click()]);await page.locator('#logout').waitFor();return page;}};}
|
||||
module.exports={setup};
|
||||
Reference in new issue
Block a user