import{M as F,p as h,c as A,e as a,z as t,f as e,g as n,h as r,F as d,A as g,k as $,o,n as u,w as P,j as J,N as M}from"./vue-CSzJdJby.js";import{_ as q}from"./ring-alt-BtllWDs8.js";import{U as G}from"./index-ncPPdFzC.js";import{H as U}from"./highlight.js-CWp04Ajj.js";import{s as K}from"./default-DS69DB32.js";import{$ as v}from"./jquery-BALIvAru.js";import{_ as I}from"./lodash-uc_7-CSk.js";import{_ as Q}from"./ReindexModal-CUkLKkWF.js";import{_ as W}from"./SizeDistributionBar-CUwS4Z3x.js";import"./index-C25aB_MX.js";import"./daterangepicker-i3LpM03M.js";import"./moment-CMyQs7Vz.js";const X={class:"row"},Y={class:"col"},Z={key:0,class:"col text-end"},R={key:0,class:"text-center"},tt=t("img",{src:q,class:"fa-fw fa-2x"},null,-1),et=[tt],st={key:1},at={class:"d-flex"},ot={class:"text-body-secondary small"},nt={class:"ms-auto"},lt={class:"btn btn-sm btn-outline-secondary dropdown-toggle",type:"button","data-bs-toggle":"dropdown","aria-haspopup":"true","aria-expanded":"false"},it={class:"dropdown-menu"},rt=t("h6",{class:"dropdown-header"},"Sort by:",-1),ct=["onClick"],dt={key:0},_t={class:"table table-sm"},ut=t("thead",null,[t("tr",null,[t("th"),e(),t("th"),e(),t("th",{class:"text-center border-start"},[t("div",{class:"d-inline-block"},[t("div",{class:"progress border rounded-0",style:{height:"7px",width:"10px"}},[t("div",{class:"progress-bar bg-cat1",role:"progressbar",style:{width:"100%"}})])]),e(`
              Heap
            `)]),e(),t("th",{class:"text-center border-start"},[t("div",{class:"d-inline-block"},[t("div",{class:"progress border rounded-0",style:{height:"7px",width:"10px"}},[t("div",{class:"progress-bar bg-cat2",role:"progressbar",style:{width:"100%"}})])]),e(`
              Indexes
            `)]),e(),t("th",{class:"text-center border-start"},[t("div",{class:"d-inline-block"},[t("div",{class:"progress border rounded-0",style:{height:"7px",width:"10px"}},[t("div",{class:"progress-bar bg-cat3",role:"progressbar",style:{width:"100%"}})])]),e(`
              Toast
            `)])])],-1),bt={class:"temboard-table"},mt=["href"],ht={key:0},yt=t("em",{class:"tablespace text-body-secondary small"},"in ",-1),pt={class:"heap text-end border-start"},xt={key:0,class:"indexes text-end border-start"},vt={class:"badge text-bg-secondary"},ft={class:"d-inline-block",style:{"min-width":"80px"}},gt={key:1,class:"indexes text-center text-body-secondary border-start small"},wt=t("em",null," No index ",-1),kt=[wt],zt={class:"temboard-toast text-end border-start"},St={colspan:"6",class:"border-top-0"},Tt={class:"d-flex"},Ct={class:"text-body-secondary small"},Nt={class:"ms-auto"},$t={class:"btn btn-sm btn-outline-secondary dropdown-toggle",type:"button","data-bs-toggle":"dropdown","aria-haspopup":"true","aria-expanded":"false"},Bt={class:"dropdown-menu"},jt=t("h6",{class:"dropdown-header"},"Sort by:",-1),Et=["onClick"],Ft={key:1},At={class:"table table-sm table-query table-striped table-bordered"},Ut={class:"index"},It=t("br",null,null,-1),qt=t("em",{class:"text-body-secondary small"},"on ",-1),Dt=["href"],Ht={key:0},Ot=t("em",{class:"text-body-secondary small"},"in ",-1),Vt={class:"index-size text-end align-middle"},Lt={class:"index-scans align-middle text-end"},Pt={key:0,class:"badge text-bg-secondary"},Jt={class:"query",width:"80%"},Mt={class:"sql"},Gt={class:"reindex align-middle",width:"5%"},Kt=["onClick"],Qt={key:0,class:"list list-unstyled mb-0"},Wt={key:0},Xt={key:0},Yt=["title"],Zt=t("i",{class:"fa fa-clock-o"},null,-1),Rt=["title"],te=["onClick"],ee={key:1,class:"text-body-secondary"},se=t("img",{id:"loadingIndicator",src:q,class:"fa-fw"},null,-1),ae={key:2,class:"text-body-secondary"},oe={key:3,class:"text-body-secondary"},ne={__name:"Schema",props:["apiUrl","instance","database","schema","maintenanceBaseUrl","schemaApiUrl"],setup(f){U.registerLanguage("sql",K);let B;const y=f;F("instance",y.instance);const S=h(y.database);F("dbName",S);const T=h(y.schema),b=h("total_bytes"),C=h({name:["Name","asc"],total_bytes:["Database Size","desc"],tables_bytes:["Tables Size","desc"],tables_bloat_ratio:["Tables Bloat","desc"],indexes_bytes:["Indexes Size","desc"],indexes_bloat_ratio:["Indexes Bloat","desc"],toast_bytes:["Toast Size","desc"]}),p=h("total_bytes"),N=h({name:["Name"],total_bytes:["Size","desc"],bloat_ratio:["Bloat","desc"]}),w=h([]),k=h(!0),_=h({}),j=h(null),D=A(()=>{const c=C.value[b.value][1];return I.orderBy(_.value.tables,b.value,c)}),H=A(()=>{const c=N.value[p.value][1];return I.orderBy(_.value.indexes,p.value,c)});function O(){E(),z()}function E(){v.ajax({url:y.apiUrl,contentType:"application/json",success:function(c){_.value=c,_.value.tables.forEach(function(l){l.bloat_ratio=0,l.table_bytes&&(l.bloat_ratio=parseFloat((100*(l.bloat_bytes/l.table_bytes)).toFixed(1))),l.index_bloat_ratio=0,l.index_bytes&&(l.index_bloat_ratio=parseFloat((100*(l.index_bloat_bytes/l.index_bytes)).toFixed(1)))}),_.value.indexes.forEach(function(l){l.bloat_ratio=0,l.total_bytes&&(l.bloat_ratio=parseFloat((100*(l.bloat_bytes/l.total_bytes)).toFixed(1)))}),window.setTimeout(()=>{v("pre code.sql").each((l,s)=>{U.highlightBlock(s)})},1)},error:showError,complete:function(){k.value=!1}})}function z(){window.clearTimeout(B);const c=w.value.length;v.ajax({url:y.apiUrl+"/reindex/scheduled",contentType:"application/json",success:function(l){w.value=l,B=window.setTimeout(function(){z()},5e3),l.length<c&&E()},error:showError})}function V(){const c=v("#reindexForm").serializeArray(),l={},s=c.filter(function(m){return m.name=="datetime"}).map(function(m){return m.value}).join("");s&&(l.datetime=s);const i=c.filter(function(m){return m.name=="elementType"}).map(function(m){return m.value}).join(""),x=c.filter(function(m){return m.name==i}).map(function(m){return m.value}).join("");v.ajax({method:"POST",url:[y.schemaApiUrl,i,x,"reindex"].join("/"),data:JSON.stringify(l),contentType:"application/json",success:z,error:showError})}function L(c){v.ajax({method:"DELETE",url:y.maintenanceBaseUrl+"/reindex/"+c,contentType:"application/json",success:z,error:showError})}return O(),(c,l)=>(o(),a("div",null,[t("h3",X,[t("div",Y,[e(`
        Schema: `),t("strong",null,n(T.value),1)]),e(),!k.value&&_.value.size?(o(),a("div",Z,[e(`
        Size: `),t("strong",null,n(_.value.size),1)])):r("",!0)]),e(),k.value?(o(),a("div",R,et)):r("",!0),e(),k.value?r("",!0):(o(),a("div",st,[t("div",at,[t("h4",null,[e(`
          Tables `),t("span",ot,"("+n(_.value.tables.length)+")",1)]),e(),t("div",nt,[t("button",lt,`
            Sort by `+n(C.value[b.value][0]),1),e(),t("div",it,[rt,e(),(o(!0),a(d,null,g(C.value,(s,i)=>(o(),a("a",{class:"dropdown-item",href:"#",onClick:x=>b.value=i},[t("i",{class:u(["fa fa-fw",{"fa-check":b.value==i}])},null,2),e(" "+n(s[0]),1)],8,ct))),256))])])]),e(),_.value.tables.length?r("",!0):(o(),a("em",dt,"No table")),e(),t("table",_t,[ut,e(),t("tbody",null,[(o(!0),a(d,null,g(D.value,(s,i)=>(o(),a(d,null,[t("tr",{class:u({"bg-light2":i%2==0})},[t("td",bt,[t("a",{href:`/server/${f.instance.agentAddress}/${f.instance.agentPort}/maintenance/${S.value}/schema/${T.value}/table/${s.name}`},[t("strong",null,n(s.name),1)],8,mt),e(),s.tablespace?(o(),a("span",ht,[yt,e(" "+n(s.tablespace),1)])):r("",!0)]),e(),t("td",{class:u(["temboard-table-total-size","text-end",b.value=="total_bytes"?"fw-bold":""])},n(s.total_size),3),e(),t("td",pt,[s.table_bytes?(o(),a("span",{key:0,class:u(["table-size",b.value=="table_bytes"?"fw-bold":""])},n(s.table_size),3)):(o(),a(d,{key:1},[e(" - ")],64)),e(),t("small",{style:{"min-width":"70px"},class:u(["table-bloat","d-inline-block",b.value=="bloat_ratio"?"fw-bold":"text-body-secondary"])},[s.bloat_bytes?(o(),a(d,{key:0},[e(" Bloat: "+n(s.bloat_ratio.toFixed(1))+"% ",1)],64)):r("",!0)],2)]),e(),s.n_indexes?(o(),a("td",xt,[t("span",vt,n(s.n_indexes),1),e(),t("span",ft,[s.index_bytes?(o(),a("span",{key:0,class:u(["index-size",b.value=="index_bytes"?"fw-bold":""])},n(s.index_size),3)):(o(),a(d,{key:1},[e(" - ")],64))]),e(),t("small",{style:{"min-width":"70px"},class:u(["index-bloat","d-inline-block",b.value=="index_bloat_ratio"?"fw-bold":"text-body-secondary"])},[s.index_bloat_bytes?(o(),a(d,{key:0},[e(`
                      Bloat: `+n(s.index_bloat_ratio.toFixed(1))+`%
                    `,1)],64)):r("",!0)],2)])):(o(),a("td",gt,kt)),e(),t("td",zt,[s.toast_bytes?(o(),a("span",{key:0,class:u(["toast-size",b.value=="toast_bytes"?"fw-bold":""])},n(s.toast_size),3)):(o(),a(d,{key:1},[e(" - ")],64))])],2),e(),t("tr",{class:u({"bg-light2":i%2==0})},[t("td",St,[$(W,{height:"7",total:_.value.total_bytes,cat1:s.table_size,cat1raw:s.table_bytes,cat1label:"Heap",cat1bis:s.bloat_size,cat1bisraw:s.bloat_bytes||0,cat1bislabel:"Heap Bloat",cat2:s.index_size,cat2raw:s.index_bytes,cat2label:"Indexes",cat2bis:s.index_bloat_size,cat2bisraw:s.index_bloat_bytes,cat2bislabel:"Indexes Bloat",cat3:s.toast_size,cat3raw:s.toast_bytes,cat3label:"Toast"},null,8,["total","cat1","cat1raw","cat1bis","cat1bisraw","cat2","cat2raw","cat2bis","cat2bisraw","cat3","cat3raw"])])],2)],64))),256))])]),e(),t("div",Tt,[t("h4",null,[e(`
          Indexes `),t("span",Ct,"("+n(_.value.indexes.length)+")",1)]),e(),t("div",Nt,[t("button",$t,`
            Sort by `+n(N.value[p.value][0]),1),e(),t("div",Bt,[jt,e(),(o(!0),a(d,null,g(N.value,(s,i)=>(o(),a("a",{class:"dropdown-item",href:"#",onClick:x=>p.value=i},[t("i",{class:u(["fa fa-fw",{"fa-check":p.value==i}])},null,2),e(" "+n(s[0]),1)],8,Et))),256))])])]),e(),_.value.tables.length?r("",!0):(o(),a("em",Ft,"No index")),e(),$(Q,{reindexType:"index",reindexElementName:j.value,onApply:V},null,8,["reindexElementName"]),e(),t("table",At,[t("tbody",null,[(o(!0),a(d,null,g(H.value,s=>(o(),a("tr",null,[t("td",Ut,[t("strong",null,n(s.name),1),e(),t("small",null," ("+n(s.type)+") ",1),e(),It,e(),qt,e(),t("a",{href:`/server/${f.instance.agentAddress}/${f.instance.agentPort}/maintenance/${S.value}/schema/${T.value}/table/${s.tablename}`},n(s.tablename),9,Dt),e(),s.tablespace?(o(),a("span",Ht,[Ot,e(" "+n(s.tablespace),1)])):r("",!0)]),e(),t("td",Vt,[t("span",{class:u([p.value=="total_bytes"?"fw-bold":""])},n(s.total_size),3),e(),t("small",{style:{"min-width":"70px"},class:u(["d-inline-block",p.value=="bloat_ratio"?"fw-bold":"text-body-secondary"])},[s.bloat_bytes?(o(),a(d,{key:0},[e(" Bloat: "+n(s.bloat_ratio.toFixed(1))+"% ",1)],64)):r("",!0)],2)]),e(),t("td",Lt,[s.scans?(o(),a("span",Pt,n(s.scans)+" scans ",1)):r("",!0)]),e(),t("td",Jt,[t("pre",null,[t("code",Mt,n(s.def),1)])]),e(),t("td",Gt,[t("button",{class:"buttonReindex btn btn-outline-secondary btn-sm py-0","data-bs-toggle":"modal","data-bs-target":"#reindexModal",onClick:i=>j.value=s.name},`
                Reindex
              `,8,Kt),e(),w.value.length>0?(o(),a("ul",Qt,[(o(!0),a(d,null,g(w.value,i=>(o(),a(d,null,[i.index==s.name?(o(),a("li",Wt,[i.status=="todo"?(o(),a(d,{key:0},[i.status=="todo"?(o(),a("em",Xt,[t("span",{class:"text-body-secondary",title:i.datetime.toString()},[Zt,e(),t("span",{title:i.datetime.toString()},[$(J(G),{time:i.datetime},{default:P(({timeAgo:x})=>[e(n(x),1)]),_:2},1032,["time"])],8,Rt)],8,Yt)])):r("",!0),e(),i.status=="todo"?(o(),a("button",{key:1,class:"buttonCancel btn btn-link py-0",onClick:x=>L(i.id)},`
                        Cancel
                      `,8,te)):r("",!0)],64)):i.status=="doing"?(o(),a("em",ee,[se,e(`
                        in progress
                      `)])):i.status=="canceled"?(o(),a("em",ae,"canceled")):(o(),a("em",oe,n(i.status),1))])):r("",!0)],64))),256))])):r("",!0)])]))),256))])])]))]))}};M({el:"#app",components:{maintenanceschema:ne}}).mount("#app");
