Deduplicate stored upload files and retain adoption bytes until their Root is durable
This commit is contained in:
@@ -55,3 +55,15 @@ test('WorkspaceRuntime owns one depot across projects and closes it after projec
|
||||
assert.deepEqual(runtime.assetDepot.scope,{accountId,workspaceId});assert.equal(Object.isFrozen(f.storage),false);
|
||||
const p=await runtime.open(createDocument('p',[{id:'canvas',parent:null}],[]),new Map([['canvas',1]]));await adopt(p);await p.settle();const q=await runtime.open(createDocument('q',[{id:'canvas',parent:null}],[]),new Map([['canvas',1]]));await adopt(q);await q.settle();assert.equal(runtime.assetDepot.getResources().size,1);assert.equal(f.calls.filter(v=>v==='read').length,1);await runtime.close();assert.equal(f.closed,true);assert.equal(runtime.assetDepot.getResources().size,0);
|
||||
});
|
||||
|
||||
test('an older Root cannot release newly adopted bytes while its unpinned manifest is committing',async()=>{
|
||||
const f=fixture(),engine=await f.open('p',{historyLimit:1});let release,started;const commit=f.storage.commit;
|
||||
try{
|
||||
await adopt(engine);await engine.settle();engine.editor.dispatch({type:'element.remove',target:{id:'picture',incarnation:1}});await engine.settle();engine.editor.dispatch({type:'element.create',element:{...node({id:'unused',src:'unused'},'text'),componentId:'text',data:{title:'text',text:''}}});await engine.settle();
|
||||
const ready=new Promise(resolve=>started=resolve),gate=new Promise(resolve=>release=resolve);let once=true;
|
||||
f.storage.commit=async(leader,batch)=>{if(once){once=false;assert.equal(batch.depot.pins.some(([id])=>id==='shared'),false);started();await gate;}return commit(leader,batch);};
|
||||
engine.editor.updateRuntime(previous=>({...previous}));await ready;
|
||||
// GC is allowed here: the old Root has no working/history/ACK/job reference.
|
||||
f.cache.clear();assert.equal((await adopt(engine,'fresh')).status,'applied');release();await engine.settle();assert.equal(await f.cache.values().next().value.bytes.text(),'original bytes');assert.equal(f.roots.get('p').payload.document.elements.some(element=>element.id==='fresh'),true);
|
||||
}finally{release?.();f.storage.commit=commit;await engine.close();}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user