Fix Developer Console memory refresh loop in v17.6.4
This commit is contained in:
parent
14ee75cc41
commit
ba5ac5ef9c
@ -1,5 +1,7 @@
|
|||||||
(()=>{
|
(()=>{
|
||||||
'use strict';
|
'use strict';
|
||||||
|
const VERSION='17.6.4';
|
||||||
|
const RELEASE='20260907-v17-6-4-settings-orders-pdf-menu';
|
||||||
const critical=img=>img.closest('header,.brand,#sunCloudAuthGate,.sun-auth-gate')||img.id==='sunLoginLogo'||img.classList.contains('sun-live-catalog-logo');
|
const critical=img=>img.closest('header,.brand,#sunCloudAuthGate,.sun-auth-gate')||img.id==='sunLoginLogo'||img.classList.contains('sun-live-catalog-logo');
|
||||||
const tune=img=>{
|
const tune=img=>{
|
||||||
if(!(img instanceof HTMLImageElement)||critical(img))return;
|
if(!(img instanceof HTMLImageElement)||critical(img))return;
|
||||||
@ -53,39 +55,60 @@
|
|||||||
const input=e.target;if(!(input instanceof HTMLInputElement)||input.id!=='sunChatFilesV29'||guardedInputs.has(input)||typeof DataTransfer==='undefined')return;
|
const input=e.target;if(!(input instanceof HTMLInputElement)||input.id!=='sunChatFilesV29'||guardedInputs.has(input)||typeof DataTransfer==='undefined')return;
|
||||||
e.preventDefault();e.stopImmediatePropagation();guardChatFiles(input).catch(err=>{console.error('[Caterium photo compression]',err);guardedInputs.add(input);input.dispatchEvent(new Event('change',{bubbles:true}));guardedInputs.delete(input);});
|
e.preventDefault();e.stopImmediatePropagation();guardChatFiles(input).catch(err=>{console.error('[Caterium photo compression]',err);guardedInputs.add(input);input.dispatchEvent(new Event('change',{bubbles:true}));guardedInputs.delete(input);});
|
||||||
},true);
|
},true);
|
||||||
window.SunAttachmentGuard={VERSION:'17.6.3',MAX_FILE,TARGET,MAX_SIDE,compressImage,prepareAttachment};
|
window.SunAttachmentGuard={VERSION,MAX_FILE,TARGET,MAX_SIDE,compressImage,prepareAttachment};
|
||||||
|
|
||||||
let memoryData=null,memoryAt=0,memoryLoading=false;
|
let memoryData=null,memoryAt=0,memoryPromise=null,memoryTimer=0;
|
||||||
|
const MEMORY_CACHE_MS=15000,MEMORY_REFRESH_MS=30000,MEMORY_TIMEOUT_MS=8000;
|
||||||
const esc=v=>window.SunSafe?.escapeHTML?window.SunSafe.escapeHTML(String(v??'')):String(v??'');
|
const esc=v=>window.SunSafe?.escapeHTML?window.SunSafe.escapeHTML(String(v??'')):String(v??'');
|
||||||
async function loadMemory(){
|
const developerVisible=()=>document.getElementById('sun-developer-console-v22')?.classList.contains('on');
|
||||||
const now=Date.now();if(memoryLoading)return memoryData;if(memoryData&&now-memoryAt<5000)return memoryData;
|
async function loadMemory({force=false}={}){
|
||||||
const c=window.SunCloudV2?.getClient?.();if(!c)return null;memoryLoading=true;
|
const now=Date.now();if(memoryPromise)return memoryPromise;if(!force&&memoryData&&now-memoryAt<MEMORY_CACHE_MS)return memoryData;
|
||||||
try{const r=await c.rpc('sun_dev_dashboard');if(r.error)throw r.error;memoryData=r.data||null;memoryAt=Date.now();return memoryData;}catch(_){return null}finally{memoryLoading=false;}
|
const c=window.SunCloudV2?.getClient?.();if(!c)return null;
|
||||||
|
memoryPromise=(async()=>{
|
||||||
|
let timer=0;
|
||||||
|
try{
|
||||||
|
const timeout=new Promise((_,reject)=>{timer=setTimeout(()=>reject(new Error('Developer memory timeout')),MEMORY_TIMEOUT_MS)});
|
||||||
|
const rpc=Promise.resolve(c.rpc('sun_dev_dashboard'));
|
||||||
|
const r=await Promise.race([rpc,timeout]);
|
||||||
|
if(r?.error)throw r.error;memoryData=r?.data||null;memoryAt=Date.now();return memoryData;
|
||||||
|
}catch(error){console.warn('[Caterium developer memory]',error?.message||error);return memoryData}
|
||||||
|
finally{clearTimeout(timer);memoryPromise=null}
|
||||||
|
})();
|
||||||
|
return memoryPromise;
|
||||||
}
|
}
|
||||||
async function enhanceDeveloperMemory(){
|
async function enhanceDeveloperMemory({force=false}={}){
|
||||||
const view=document.getElementById('sun-developer-console-v22');if(!view?.classList.contains('on'))return;
|
const view=document.getElementById('sun-developer-console-v22');if(!view?.classList.contains('on'))return null;
|
||||||
const body=document.getElementById('sunDevBody');if(!body)return;
|
const body=document.getElementById('sunDevBody');if(!body)return null;
|
||||||
const version=document.getElementById('sunDevReleaseVersion');if(version)version.textContent='17.6.3';
|
const version=document.getElementById('sunDevReleaseVersion');if(version)version.textContent=VERSION;
|
||||||
const d=await loadMemory();if(!d||!view.classList.contains('on'))return;
|
const d=await loadMemory({force});if(!d||!developerVisible())return d;
|
||||||
let box=document.getElementById('sunDevMemoryV1761');if(!box){box=document.createElement('div');box.id='sunDevMemoryV1761';box.className='sun-dev-grid';box.style.marginBottom='12px';body.prepend(box);}
|
let box=document.getElementById('sunDevMemoryV1761');if(!box){box=document.createElement('div');box.id='sunDevMemoryV1761';box.className='sun-dev-grid';box.style.marginBottom='12px';body.prepend(box);}
|
||||||
box.innerHTML=`<div class="sun-dev-kpi"><small>Память сервера</small><b>${esc(d.server_size||d.database_size||'—')}</b></div><div class="sun-dev-kpi"><small>База PostgreSQL</small><b>${esc(d.database_size||'—')}</b></div><div class="sun-dev-kpi"><small>Файлы Storage</small><b>${esc(d.storage_size||'—')}</b></div><div class="sun-dev-kpi"><small>Объектов Storage</small><b>${Number(d.storage_objects||0)}</b></div>`;
|
const html=`<div class="sun-dev-kpi"><small>Память сервера</small><b>${esc(d.server_size||d.database_size||'—')}</b></div><div class="sun-dev-kpi"><small>База PostgreSQL</small><b>${esc(d.database_size||'—')}</b></div><div class="sun-dev-kpi"><small>Файлы Storage</small><b>${esc(d.storage_size||'—')}</b></div><div class="sun-dev-kpi"><small>Объектов Storage</small><b>${Number(d.storage_objects||0)}</b></div>`;
|
||||||
|
if(box.innerHTML!==html)box.innerHTML=html;
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
|
function scheduleMemoryRefresh(delay=80,force=false){setTimeout(()=>{if(developerVisible())enhanceDeveloperMemory({force}).catch(()=>{})},delay)}
|
||||||
|
function startMemoryTimer(){if(memoryTimer)return;memoryTimer=setInterval(()=>{if(!document.hidden&&developerVisible())enhanceDeveloperMemory({force:true}).catch(()=>{})},MEMORY_REFRESH_MS)}
|
||||||
|
|
||||||
function loadHotfix(){
|
function loadHotfix(){
|
||||||
if(window.SunHotfixV1763||document.getElementById('sunHotfixV1763Script'))return;
|
if(window.SunHotfixV1763||document.getElementById('sunHotfixV1763Script'))return;
|
||||||
const script=document.createElement('script');script.id='sunHotfixV1763Script';script.src='core/hotfix-v1763.js?v=20260907-v17-6-3-developer-hotfix';script.async=true;script.onerror=()=>console.error('[Caterium] Не загрузился модуль hotfix-v1763.js');document.head.appendChild(script);
|
const script=document.createElement('script');script.id='sunHotfixV1763Script';script.src=`core/hotfix-v1763.js?v=${RELEASE}`;script.async=true;script.onerror=()=>console.error('[Caterium] Не загрузился модуль hotfix-v1763.js');document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
function loadOpsUX(){
|
function loadOpsUX(){
|
||||||
if(window.SunOpsUXV1762||document.getElementById('sunOpsUXV1762Script'))return;
|
if(window.SunOpsUXV1762||document.getElementById('sunOpsUXV1762Script'))return;
|
||||||
const script=document.createElement('script');script.id='sunOpsUXV1762Script';script.src='core/ops-ux-v1762.js?v=20260907-v17-6-3-developer-hotfix';script.async=true;script.onerror=()=>console.error('[Caterium] Не загрузился модуль ops-ux-v1762.js');document.head.appendChild(script);
|
const script=document.createElement('script');script.id='sunOpsUXV1762Script';script.src=`core/ops-ux-v1762.js?v=${RELEASE}`;script.async=true;script.onerror=()=>console.error('[Caterium] Не загрузился модуль ops-ux-v1762.js');document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
function loadUXFix(){
|
||||||
|
if(window.SunUXFixV1764||document.getElementById('sunUXFixV1764Script'))return;
|
||||||
|
const script=document.createElement('script');script.id='sunUXFixV1764Script';script.src=`core/ux-fixes-v1764.js?v=${RELEASE}`;script.async=true;script.onerror=()=>console.error('[Caterium] Не загрузился модуль ux-fixes-v1764.js');document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
const start=()=>{
|
const start=()=>{
|
||||||
loadHotfix();loadOpsUX();scan(document);
|
loadHotfix();loadOpsUX();loadUXFix();scan(document);startMemoryTimer();
|
||||||
const mo=new MutationObserver(records=>{records.forEach(r=>r.addedNodes.forEach(n=>{if(n.nodeType===1)scan(n)}));enhanceDeveloperMemory();});
|
const mo=new MutationObserver(records=>{records.forEach(r=>r.addedNodes.forEach(n=>{if(n.nodeType===1)scan(n)}));});
|
||||||
mo.observe(document.documentElement,{childList:true,subtree:true});
|
mo.observe(document.documentElement,{childList:true,subtree:true});
|
||||||
document.addEventListener('click',e=>{if(e.target.closest('#sunDeveloperNavV22,[data-dev-tab],#sunDevRefresh'))setTimeout(enhanceDeveloperMemory,100)},true);
|
document.addEventListener('click',e=>{if(e.target.closest('#sunDeveloperNavV22,[data-dev-tab],#sunDevRefresh'))scheduleMemoryRefresh(100,true)},true);
|
||||||
window.addEventListener('sun:cloud-state-applied',()=>setTimeout(enhanceDeveloperMemory,150));
|
window.addEventListener('sun:cloud-state-applied',()=>scheduleMemoryRefresh(180,true));
|
||||||
setInterval(()=>{if(document.getElementById('sun-developer-console-v22')?.classList.contains('on'))enhanceDeveloperMemory();},5000);
|
document.addEventListener('visibilitychange',()=>{if(!document.hidden&&developerVisible())scheduleMemoryRefresh(50,false)});
|
||||||
window.SunPerformance={scanImages:()=>scan(document),refreshDeveloperMemory:enhanceDeveloperMemory,loadHotfix,loadOpsUX,disconnect:()=>mo.disconnect()};
|
window.SunPerformance={VERSION,scanImages:()=>scan(document),refreshDeveloperMemory:(force=true)=>enhanceDeveloperMemory({force}),loadHotfix,loadOpsUX,loadUXFix,disconnect:()=>{mo.disconnect();if(memoryTimer){clearInterval(memoryTimer);memoryTimer=0;}}};
|
||||||
};
|
};
|
||||||
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});else start();
|
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});else start();
|
||||||
})();
|
})();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user