import{M as B,p as h,c as A,e as l,z as e,f as t,g as c,h as r,k as p,w as L,j as F,F as v,A as $,o as i,n as q,N as ne}from"./vue-CSzJdJby.js";import{_ as P}from"./ring-alt-BtllWDs8.js";import{U as I}from"./index-ncPPdFzC.js";import{H as J}from"./highlight.js-CWp04Ajj.js";import{s as oe}from"./default-DS69DB32.js";import{$ as _}from"./jquery-BALIvAru.js";import{_ as R}from"./lodash-uc_7-CSk.js";import{_ as le,a as ce,b as ie,c as de,d as ue}from"./VacuumModal-Df67OX_Q.js";import{_ as re}from"./ReindexModal-CUkLKkWF.js";import{_ as _e}from"./SizeDistributionBar-CUwS4Z3x.js";import"./index-C25aB_MX.js";import"./daterangepicker-i3LpM03M.js";import"./moment-CMyQs7Vz.js";const me={key:0,class:"text-center"},be=e("img",{src:P,class:"fa-fw fa-2x"},null,-1),he=[be],pe={key:1},ye={class:"row mb-2"},ve={class:"col"},fe={class:"row"},ge={class:"col"},xe=e("dt",null,"Total",-1),we=e("br",null,null,-1),ze={class:"text-body-secondary"},ke={class:"text-body-secondary"},Te={class:"col"},Ae=e("dt",null,[t(`
              Heap
              `),e("span",{class:"bg-cat1 legend fa-fw d-inline-block"}," ")],-1),Ee=e("br",null,null,-1),je={class:"text-body-secondary"},Ue={class:"small"},Ne={class:"col"},Ce=e("dt",null,[t(`
              Indexes
              `),e("span",{class:"bg-cat2 legend fa-fw d-inline-block"}," ")],-1),Se=e("br",null,null,-1),Ve={class:"text-body-secondary"},Be={class:"small"},Le={class:"col"},Fe=e("dt",null,[e("span",{class:"bg-secondary legend fa-fw d-inline-block"}," "),t(`
              Toast
            `)],-1),$e={class:"col"},qe=e("dt",null,"Fill Factor",-1),Ie={class:"row"},Me={class:"col-4"},Oe=["title"],De={key:0},He={key:1},Ye={key:2},Je={key:0,class:"text-body-secondary small"},Re=e("br",null,null,-1),Pe={class:"col-4"},Xe=["title"],Ze={key:0},Ge={key:1},Ke={key:2},Qe=e("br",null,null,-1),We={class:"row"},et={class:"col-4"},tt=e("button",{id:"buttonAnalyze",type:"button",class:"btn btn-outline-secondary","data-bs-toggle":"modal","data-bs-target":"#analyzeModal"},`
              ANALYZE
            `,-1),at={class:"col-4"},st=e("button",{id:"buttonVacuum",type:"button",class:"btn btn-outline-secondary","data-bs-toggle":"modal","data-bs-target":"#vacuumModal"},`
              VACUUM
            `,-1),nt={class:"col-4"},ot={class:"row"},lt={class:"col"},ct={key:0,class:"text-danger"},it=e("i",{class:"fa fa-exclamation-triangle"},null,-1),dt=e("br",null,null,-1),ut=e("span",{class:"ps-4 text-body-secondary margin-start"},`
              Out of date analyzes can result in stats not being accurate, which eventually leads to slow queries.
            `,-1),rt={key:1,class:"text-danger"},_t=e("i",{class:"fa fa-exclamation-triangle"},null,-1),mt=e("br",null,null,-1),bt=e("span",{class:"ps-4 text-body-secondary margin-start"}," Dead tuples waste space and slow down queries. ",-1),ht={key:2,class:"text-danger"},pt=e("i",{class:"fa fa-exclamation-triangle"},null,-1),yt=e("br",null,null,-1),vt=e("span",{class:"ps-4 text-body-secondary margin-start"},`
              Table bloat wastes space and slows down queries.
            `,-1),ft={key:3,class:"text-danger"},gt=e("i",{class:"fa fa-exclamation-triangle"},null,-1),xt=e("br",null,null,-1),wt=e("span",{class:"ps-4 text-body-secondary margin-start"},`
              Index bloat wastes space and slows down queries.
            `,-1),zt={class:"d-flex"},kt={class:"text-body-secondary small"},Tt={class:"ms-auto"},At={class:"btn btn-sm btn-outline-secondary dropdown-toggle",type:"button","data-bs-toggle":"dropdown","aria-haspopup":"true","aria-expanded":"false"},Et={class:"dropdown-menu"},jt=e("h6",{class:"dropdown-header"},"Sort by:",-1),Ut=["onClick"],Nt={class:"table table-sm table-query table-striped table-bordered"},Ct={class:"index-name align-middle"},St={key:0},Vt=e("em",{class:"text-body-secondary small"},"in ",-1),Bt={class:"index-size text-end align-middle"},Lt={class:"index-scans align-middle text-end"},Ft={key:0,class:"badge text-bg-secondary"},$t={class:"query",width:"80%"},qt={class:"sql"},It={class:"reindex align-middle",width:"5%"},Mt=["onClick"],Ot={key:0,class:"list list-unstyled mb-0"},Dt={key:0},Ht={key:0},Yt=["title"],Jt=e("i",{class:"fa fa-clock-o"},null,-1),Rt=["onClick"],Pt={key:1,class:"text-body-secondary"},Xt=e("img",{id:"loadingIndicator",src:P,class:"fa-fw"},null,-1),Zt={key:2,class:"text-body-secondary"},Gt={key:3,class:"text-body-secondary"},Kt={__name:"Table",props:["apiUrl","instance","database","schema","table","maintenanceBaseUrl","schemaApiUrl"],setup(X){J.registerLanguage("sql",oe);let M,O,D;const m=X;B("instance",m.instance);const Z=h(m.database);B("dbName",Z);const E=h(m.table);B("tableName",E);const y=h("total_bytes"),j=h({name:["Name","asc"],total_bytes:["Size","desc"],bloat_ratio:["Bloat","desc"]}),U=h(!0),a=h({}),N=h([]),C=h([]),f=h([]),S=h(""),V=h(null);function G(){g(),x(),w(),z()}const K=A(()=>{const n=j.value[y.value][1];return R.orderBy(a.value.indexes,y.value,n)}),Q=A(()=>R.filter(f.value,function(n){return n.table==E.value}));function g(){_.ajax({url:m.apiUrl,contentType:"application/json",success:function(n){a.value=n,n.indexes.forEach(function(o){o.bloat_ratio=0,o.total_bytes&&(o.bloat_ratio=parseFloat((100*(o.bloat_bytes/o.total_bytes)).toFixed(1)))}),window.setTimeout(()=>{_("pre code.sql").each(function(o,s){J.highlightBlock(s)})},1)},error:showError,complete:function(){U.value=!1}})}function x(){window.clearTimeout(M);const n=N.value.length;_.ajax({url:m.apiUrl+"/vacuum/scheduled",contentType:"application/json",success:function(o){N.value=o,M=window.setTimeout(function(){x()},5e3),o.length<n&&g()},error:showError})}function W(){const n=_("#vacuumForm").serializeArray(),o=n.filter(function(u){return u.name=="mode"}).map(function(u){return u.value}).join(","),s={};o&&(s.mode=o);const d=n.filter(function(u){return u.name=="datetime"}).map(function(u){return u.value}).join("");d&&(s.datetime=d),_.ajax({method:"POST",url:m.apiUrl+"/vacuum",data:JSON.stringify(s),contentType:"application/json",success:x,error:showError})}function ee(n){_.ajax({method:"DELETE",url:m.maintenanceBaseUrl+"/vacuum/"+n,contentType:"application/json",success:x,error:showError})}function w(){window.clearTimeout(O);const n=C.value.length;_.ajax({url:m.apiUrl+"/analyze/scheduled",contentType:"application/json",success:function(o){C.value=o,O=window.setTimeout(function(){w()},5e3),o.length<n&&g()},error:showError})}function te(){const n=_("#analyzeForm").serializeArray(),o=n.filter(function(u){return u.name=="mode"}).map(function(u){return u.value}).join(","),s={};o&&(s.mode=o);const d=n.filter(function(u){return u.name=="datetime"}).map(function(u){return u.value}).join("");d&&(s.datetime=d),_.ajax({method:"POST",url:m.apiUrl+"/analyze",data:JSON.stringify(s),contentType:"application/json",success:w,error:showError})}function ae(n){_.ajax({method:"DELETE",url:m.maintenanceBaseUrl+"/analyze/"+n,contentType:"application/json",success:w,error:showError})}function z(){window.clearTimeout(D);const n=f.value.length;_.ajax({url:m.schemaApiUrl+"/reindex/scheduled",contentType:"application/json",success:function(o){f.value=o,D=window.setTimeout(function(){z()},5e3),o.length<n&&g()},error:showError})}function se(){const n=_("#reindexForm").serializeArray(),o={},s=n.filter(function(b){return b.name=="datetime"}).map(function(b){return b.value}).join("");s&&(o.datetime=s);const d=n.filter(function(b){return b.name=="elementType"}).map(function(b){return b.value}).join(""),u=n.filter(function(b){return b.name==d}).map(function(b){return b.value}).join("");_.ajax({method:"POST",url:[m.schemaApiUrl,d,u,"reindex"].join("/"),data:JSON.stringify(o),contentType:"application/json",success:z,error:showError})}function H(n){_.ajax({method:"DELETE",url:m.maintenanceBaseUrl+"/reindex/"+n,contentType:"application/json",success:z,error:showError})}function Y(n){return function(){let o=!1,s=null;const d=a.value["last_"+n],u=a.value["last_auto"+n];return!d&&u?(o=!0,s=u):d&&!u?s=d:(o=u>d,s=o?u:d),{auto:o,date:s}}}const k=A(Y("vacuum")),T=A(Y("analyze"));return G(),(n,o)=>(i(),l("div",null,[e("h3",null,[t(`
      Table: `),e("strong",null,c(E.value),1)]),t(),U.value?(i(),l("div",me,he)):r("",!0),t(),U.value?r("",!0):(i(),l("div",pe,[e("div",ye,[e("div",ve,[p(_e,{height:"10",total:a.value.total_bytes,cat1:a.value.table_size,cat1raw:a.value.table_bytes,cat1label:"Heap",cat1bis:a.value.bloat_size,cat1bisraw:a.value.bloat_bytes||0,cat1bislabel:"Heap Bloat",cat2:a.value.index_size,cat2raw:a.value.index_bytes,cat2label:"Indexes",cat2bis:a.value.index_bloat_size,cat2bisraw:a.value.index_bloat_bytes,cat2bislabel:"Indexes Bloat",cat3:a.value.toast_size,cat3raw:a.value.toast_bytes,cat3label:"Toast"},null,8,["total","cat1","cat1raw","cat1bis","cat1bisraw","cat2","cat2raw","cat2bis","cat2bisraw","cat3","cat3raw"])])]),t(),e("div",fe,[e("div",ge,[e("dl",null,[xe,t(),e("dd",null,[t(c(a.value.total_size)+" ",1),we,t(),e("span",ze,"~ "+c(a.value.row_estimate)+" rows",1),t(),e("small",ke,"(~ "+c(a.value.n_dead_tup)+" dead)",1)])])]),t(),e("div",Te,[e("dl",null,[Ae,t(),e("dd",null,[t(c(a.value.table_size)+" ",1),Ee,t(),e("em",je,[t(`
                Bloat:
                `+c(parseInt(a.value.bloat_bytes/a.value.table_bytes*100))+`%
                `,1),e("span",Ue," ("+c(a.value.bloat_size)+") ",1)])])])]),t(),e("div",Ne,[e("dl",null,[Ce,t(),e("dd",null,[t(c(a.value.index_size)+" ",1),Se,t(),e("em",Ve,[t(`
                Bloat:
                `+c(parseInt(a.value.index_bloat_bytes/a.value.index_bytes*100))+`%
                `,1),e("span",Be," ("+c(a.value.index_bloat_size)+") ",1)])])])]),t(),e("div",Le,[e("dl",null,[Fe,t(),e("dd",null,c(a.value.toast_size),1)])]),t(),e("div",$e,[e("dl",null,[qe,t(),e("dd",null,c(a.value.fillfactor)+"%",1)])])]),t(),e("div",Ie,[e("div",Me,[t(`
          Last ANALYZE:
          `),e("em",{title:T.value.date},[T.value.date?(i(),l("strong",De,[p(F(I),{time:T.value.date},{default:L(({timeAgo:s})=>[t(c(s),1)]),_:1},8,["time"])])):(i(),l("span",He,"N/A")),t(),T.value.auto?(i(),l("span",Ye,"(auto)")):r("",!0)],8,Oe),t(),a.value.n_mod_since_analyze?(i(),l("span",Je,`
            (~ `+c(a.value.n_mod_since_analyze)+` rows modified since then)
          `,1)):r("",!0),t(),Re,t(),e("small",null,c(a.value.analyze_count)+" analyzes - "+c(a.value.autoanalyze_count)+" auto analyzes ",1)]),t(),e("div",Pe,[t(`
          Last VACUUM:
          `),e("em",{title:k.value.date},[k.value.date?(i(),l("strong",Ze,[p(F(I),{time:k.value.date},{default:L(({timeAgo:s})=>[t(c(s),1)]),_:1},8,["time"])])):(i(),l("span",Ge,"N/A")),t(),k.value.auto?(i(),l("span",Ke,"(auto)")):r("",!0)],8,Xe),t(),Qe,t(),e("small",null,c(a.value.vacuum_count)+" vacuums - "+c(a.value.autovacuum_count)+" auto vacuums ",1)])]),t(),e("div",We,[e("div",et,[e("div",null,[tt,t(),p(de,{onApply:te}),t(),p(le,{scheduledAnalyzes:C.value,onCancel:ae},null,8,["scheduledAnalyzes"])])]),t(),e("div",at,[e("div",null,[st,t(),p(ue,{onApply:W}),t(),p(ce,{scheduledVacuums:N.value,onCancel:ee},null,8,["scheduledVacuums"])])]),t(),e("div",nt,[e("div",null,[e("button",{id:"buttonReindex",type:"button",class:"btn btn-outline-secondary","data-bs-toggle":"modal","data-bs-target":"#reindexModal",onClick:o[0]||(o[0]=s=>{S.value="table",V.value=a.value.name})},`
              REINDEX
            `),t(),p(re,{reindexType:S.value,reindexElementName:V.value,onApply:se},null,8,["reindexType","reindexElementName"]),t(),p(ie,{scheduledReindexes:Q.value,onCancel:H},null,8,["scheduledReindexes"])])])]),t(),e("div",ot,[e("div",lt,[a.value.n_mod_since_analyze/a.value.n_live_tup>.5?(i(),l("p",ct,[it,t(`The number of modified rows since last analyze is high, you should
            consider lauching an ANALYZE
            `),dt,t(),ut])):r("",!0),t(),a.value.n_dead_tup/a.value.n_live_tup>.1?(i(),l("p",rt,[_t,t(`The number of dead tuples is high, you should consider running a
            VACUUM.
            `),mt,t(),bt])):r("",!0),t(),a.value.bloat_bytes/a.value.table_bytes>.5?(i(),l("p",ht,[pt,t(`Overall table bloat is high. You should consider running a Full
            VACUUUM.
            `),yt,t(),vt])):r("",!0),t(),a.value.index_bloat_bytes/a.value.index_bytes>.5?(i(),l("p",ft,[gt,t(`Overall index bloat is high. You should consider running a Full
            VACUUUM or REINDEX.
            `),xt,t(),wt])):r("",!0)])]),t(),e("div",zt,[e("h4",null,[t(`
          Indexes `),e("span",kt,"("+c(a.value.indexes.length)+")",1)]),t(),e("div",Tt,[e("button",At,`
            Sort by `+c(j.value[y.value][0]),1),t(),e("div",Et,[jt,t(),(i(!0),l(v,null,$(j.value,(s,d)=>(i(),l("a",{class:"dropdown-item",href:"#",onClick:u=>y.value=d},[e("i",{class:q(["fa fa-fw",{"fa-check":y.value==d}])},null,2),t(" "+c(s[0]),1)],8,Ut))),256))])])]),t(),e("table",Nt,[e("tbody",null,[(i(!0),l(v,null,$(K.value,s=>(i(),l("tr",null,[e("td",Ct,[e("strong",null,c(s.name),1),t(),e("small",null," ("+c(s.type)+") ",1),t(),s.tablespace?(i(),l("span",St,[Vt,t(" "+c(s.tablespace),1)])):r("",!0)]),t(),e("td",Bt,[e("span",{class:q([y.value=="total_bytes"?"fw-bold":""])},c(s.total_size),3),t(),e("small",{style:{"min-width":"70px"},class:q(["index-bloat","d-inline-block",y.value=="bloat_ratio"?"fw-bold":"text-body-secondary"])},[s.bloat_bytes?(i(),l(v,{key:0},[t(" Bloat: "+c(s.bloat_ratio.toFixed(1))+"% ",1)],64)):r("",!0)],2)]),t(),e("td",Lt,[s.scans?(i(),l("span",Ft,c(s.scans)+" scans ",1)):r("",!0)]),t(),e("td",$t,[e("pre",null,[e("code",qt,c(s.def),1)])]),t(),e("td",It,[e("button",{class:"buttonReindex btn btn-outline-secondary btn-sm py-0","data-bs-toggle":"modal","data-bs-target":"#reindexModal",onClick:d=>{S.value="index",V.value=s.name}},`
                Reindex
              `,8,Mt),t(),f.value.length>0?(i(),l("ul",Ot,[(i(!0),l(v,null,$(f.value,d=>(i(),l(v,null,[d.index==s.name?(i(),l("li",Dt,[d.status=="todo"?(i(),l(v,{key:0},[d.status=="todo"?(i(),l("em",Ht,[e("span",{class:"text-body-secondary",title:d.datetime.toString()},[Jt,t(` 
                          `),p(F(I),{time:d.datetime},{default:L(({timeAgo:u})=>[t(c(u),1)]),_:2},1032,["time"])],8,Yt)])):r("",!0),t(),d.status=="todo"?(i(),l("button",{key:1,class:"buttonCancel btn btn-link py-0",onClick:u=>H(d.id)},`
                        Cancel
                      `,8,Rt)):r("",!0)],64)):d.status=="doing"?(i(),l("em",Pt,[Xt,t(`
                        in progress
                      `)])):d.status=="canceled"?(i(),l("em",Zt,"canceled")):(i(),l("em",Gt,c(d.status),1))])):r("",!0)],64))),256))])):r("",!0)])]))),256))])])]))]))}};ne({el:"#app",components:{maintenancetable:Kt}}).mount("#app");
