const{createApp}=Vue const{createVuetify,useGoTo,useDisplay}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},theme:{dark:false,},nav:{showDrawer:false,showTOC:true,tocPanel:0,tab:'account',post:{discussionId:6638,currentPage:1,targetPage:1,total:19,anchor:0,goToOptions:{container:null,duration:0,easing:'easeInOutCubic',offset:-100,},worker:null,task:[],active:[],apiLock:[],originLike:new Map([]),},related:{block:1,}},search:{width:80,text:null,loading:false,},tags:[{id:23,url:'/t/693e74086a045c75637737750d38',name:'Postgresql',color:'#66BB6A',icon:'mdi-tag-heart',},],posts:[{id:81621,num:0,uid:5849,content:'去年我好像问过这个问题\u003Cbr\u003E最终我用 docker 在 vps 上跑了一个实例……\u003Cbr\u003E\u003Cbr\u003E考虑有高性价比的,就从 docker 上迁走\u003Cbr\u003E要求支持扩展,续费不涨价\u003Cbr\u003E\u003Cbr\u003E在阿里云上看到有一年 200 多的,但仅仅是第一年,续费价格 1k 多,所以暂不考虑',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 13:41:37',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81622,num:1,uid:14072,content:'数据库很难把, 真要高性价比的小厂你赶上吗...\u003Cbr\u003E\u003Cbr\u003E自己不想弄的话, 可以试试 openGauss, 很久没弄过了, 不过国内这种配套都是比较全的, 比如运维管理面板啥的, 不过性能我记得 openGauss 5 的时候和 Postgres 15 对比测过, 不严谨, 随便测, 性能是差一些, 不是很多.\u003Cbr\u003E\u003Cbr\u003E其他的可以研究 Pg 插件 Citus, 微软的分布式插件, 还有 CockroachDB (蟑螂 DB) 兼容 Pg 协议',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 15:16:54',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81623,num:2,uid:14951,content:'纳米项目用托管的 postgresql 没有性价比,建议自搭',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 15:23:48',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81624,num:3,uid:14952,content:'CockroachDB+1,直接用官方的云服务,应该是有 10G 的免费额度',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 15:24:28',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81625,num:4,uid:14953,content:'必须国内?我现在用的 neon ,给的免费额度足够小项目用了。https://console.neon.tech',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 15:52:17',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81626,num:5,uid:14953,content:'CockroachDB 的免费额度也很香。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 15:52:44',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81627,num:6,uid:3012,content:'https://free-for.dev/#/?id\u003Dmanaged-data-services',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 15:56:39',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81628,num:7,uid:14954,content:'关键能装插件不',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 16:23:13',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81629,num:8,uid:14955,content:'自己拿云服务 EC2 搭建(不要用轻量云) 定期用脚本备份',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 16:26:23',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81630,num:9,uid:10719,content:'哪位大佬帮忙普及下:纳米项目 是啥东西',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 17:23:14',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81631,num:10,uid:14956,content:'很小的项目的意思吧',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 17:27:33',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81632,num:11,uid:8050,content:'我还以为是什么材料学交叉项目,实验数据要存到数据库里',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 17:43:11',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81633,num:12,uid:790,content:'sqlite 跑吧,纳米项目了,也该用纳米数据库',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 17:45:06',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81634,num:13,uid:11084,content:'#12 \u003Cimg src\u003D\"https://i.imgur.com/Iy0taMy.png\"\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-26 18:42:29',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81635,num:14,uid:7228,content:'哈哈哈,没毛病。sqlite 用明白了,也就差不多可以换了。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 08:24:55',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81636,num:15,uid:14957,content:'为什么不要用轻量云?',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 08:43:42',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81637,num:16,uid:14955,content:'说的不准确 不要用突发性能实例 aws 的搞混了',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 09:11:23',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81638,num:17,uid:5849,content:'\u003Cbr\u003E备份有什么好建议?简单粗暴的 pg_dump 整个数据库?',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 09:25:30',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:81639,num:18,uid:14955,content:'定时 pg_dump',ipRegion:'',updatedByUid:0,createdAt:'2025-03-27 09:37:22',updatedAt:'2025-03-28 10:45:55',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[14951,{uid:14951,url:'/u/2a3302546a045d73696f576f135f0702',avatar:'/a/2a3302546a045d73696f576f135f0702',username:'tqyq88🤖',}],[14955,{uid:14955,url:'/u/1c7f45156a045d73696f536f345a2030',avatar:'/a/1c7f45156a045d73696f536f345a2030',username:'RadishWind🤖',}],[3012,{uid:3012,url:'/u/6a337b206a045c74606b546f101d2206',avatar:'/a/6a337b206a045c74606b546f101d2206',username:'lower🤖',}],[14952,{uid:14952,url:'/u/28286a096a045d73696f546f273c6a70',avatar:'/a/28286a096a045d73696f546f273c6a70',username:'chenuu🤖',}],[7228,{uid:7228,url:'/u/133077346a045c7062685e6f430b0b0a',avatar:'/a/133077346a045c7062685e6f430b0b0a',username:'zealotxxxx🤖',}],[11084,{uid:11084,url:'/u/3d287e036a045d766062526f3f38183e',avatar:'/a/3d287e036a045d766062526f3f38183e',username:'sunqi1993🤖',}],[5849,{uid:5849,url:'/u/6b1e660b6a045c72686e5f6f30200213',avatar:'/a/6b1e660b6a045c72686e5f6f30200213',username:'wencan🤖',}],[14954,{uid:14954,url:'/u/350d5c346a045d73696f526f355e1831',avatar:'/a/350d5c346a045d73696f526f355e1831',username:'frank42a🤖',}],[14956,{uid:14956,url:'/u/182b70286a045d73696f506f24221017',avatar:'/a/182b70286a045d73696f506f24221017',username:'xiandao7997🤖',}],[10719,{uid:10719,url:'/u/0b714a216a045d77676b5f6f23063e35',avatar:'/a/0b714a216a045d77676b5f6f23063e35',username:'cccssss🤖',}],[14072,{uid:14072,url:'/u/6b0054216a045d73606d546f22246577',avatar:'/a/6b0054216a045d73606d546f22246577',username:'luting🤖',}],[790,{uid:790,url:'/u/3410535f6a045c776763566f41193b20',avatar:'/a/3410535f6a045c776763566f41193b20',username:'macaodoll🤖',}],[14957,{uid:14957,url:'/u/323354186a045d73696f516f010c1a06',avatar:'/a/323354186a045d73696f516f010c1a06',username:'ku360517703🤖',}],[8050,{uid:8050,url:'/u/6b2f54346a045c7f606f566f3a086771',avatar:'/a/6b2f54346a045c7f606f566f3a086771',username:'maokg🤖',}],[14953,{uid:14953,url:'/u/201b0a5e6a045d73696f556f015d1d70',avatar:'/a/201b0a5e6a045d73696f556f015d1d70',username:'springz🤖',}],]),related:[{title:'你们会在数据库字段里存 json 字符串吗',url:'/d/173f54286a045c77606a56754f50626a2b01620a',},{title:'请教一个关于 PostgreSQL 连接被 Server 关闭的问题',url:'/d/6d19073a6a045c77606a5673475f656a0b0d6363',},],} const App={setup(){const goTo=useGoTo() const{mdAndUp}=useDisplay() return{goTo,mdAndUp}},data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)} if(this.nav.post.total>(this.nav.post.currentPage-1)*100+20){let moreLen=100 if(this.nav.post.total({id:null,num:(this.nav.post.currentPage-1)*100+v,uid:null,content:null,ipRegion:null,updatedByUid:null,createdAt:null,updatedAt:null,mentionNum:null,mentionedBy:null,mentionUsers:null,likeUsers:null,})) this.posts.push(...morePosts.slice(20))} this.workerStart() const hash=window.location.hash const match=hash.match(/#(\d+)/) if(match){const n=parseInt(match[1],10) if(n>=(this.nav.post.currentPage-1)*100&&n{this.jumpTo(n)})}} this.$nextTick(()=>{this.addHeadingIds() tocbot.init({tocSelector:'.toc',contentSelector:'#post-content-0',headingSelector:'h2, h3, h4',headingsOffset:100,scrollSmoothOffset:-100,scrollSmooth:true,collapseDepth:6,onClick:function(e){setTimeout(()=>{history.replaceState(null,'',window.location.pathname+window.location.search)},0)},}) tocbot.refresh()});},beforeUnmount(){this.workerStop() if(this.quill){this.quill.destroy() this.quill=null}},computed:{dposts(){return this.posts.slice(20);},},created(){},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},toPage(){let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,this.nav.post.targetPage>1?`/${this.nav.post.targetPage}`:'') window.location.href=url},toLoadRelated({done}){if(this.my&&this.my.uid){this.apiLoadRelated({done})}else{done('ok')}},workerStart(){this.nav.post.worker=setInterval(()=>{this.workerLoad()},500);},workerStop(){if(this.nav.post.worker){clearInterval(this.nav.post.worker);this.nav.post.worker=null;}},async jumpTo(num){const page=Math.floor(num/100)+1 const i=num-(page-1)*100 if(page===this.nav.post.currentPage){this.goTo("#post-"+num,this.nav.post.goToOptions) if(!this.posts[i].id){const block=Math.floor(num/20)+1 this.nav.post.apiLock[block]=true await this.apiLoadPosts(block) this.$nextTick(()=>{this.goTo("#post-"+num,this.nav.post.goToOptions)})}}else{let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,page>1?`/${page}`:'') url=url+"#"+num window.location.href=url}},postIntersect(num){return(isIntersecting,entries,observer)=>{if(isIntersecting){this.nav.post.task.push(num) this.nav.post.active.push(num) this.nav.post.active=this.nav.post.active.filter(item=>Math.abs(item-num)<=5) this.nav.post.active.sort((a,b)=>a-b)}else{this.nav.post.active=this.nav.post.active.filter(item=>item!==num)} if(this.nav.post.active[0]){this.nav.post.anchor=this.nav.post.active[0]}else{this.nav.post.anchor=0}}},async apiLoadPosts(block){try{const response=await axios.post('/fapi/v1/post/block/'+block,{discussionId:this.nav.post.discussionId,}) if(response.data.code===0){response.data.data.posts.forEach(post=>{const i=post.num%100 Object.assign(this.posts[i],post)}) response.data.data.users.forEach(user=>{this.usersMap.set(user.uid,user)})}else{this.failureAlert('回帖数据加载失败: '+response.data.msg)}}catch(error){this.failureAlert('回帖数据加载失败: '+error)} this.nav.post.apiLock[block]=false},workerLoad(){while(this.nav.post.task.length){const num=this.nav.post.task.pop() const i=num-(this.nav.post.currentPage-1)*100 if(!this.posts[i].id){const block=Math.floor(num/20)+1 if(!this.nav.post.apiLock[block]){this.nav.post.apiLock[block]=true this.apiLoadPosts(block)}}}},getTimeInfo(t){if(!t){return ""} const now=new Date();const then=new Date(t);const diff=now-then;const minute=60*1000;const hour=minute*60;const day=hour*24;const month=day*30;const year=month*12;if(diffpost.num===num) if(!post){return "#"+num} const uid=post.uid const username=this.usersMap.get(uid)?.username if(!username){return "#"+num} return username},getUsernameByPostId(id){const post=this.posts.find(post=>post.id===id) if(!post){return "#"+this.getPostNumByPostId(id)} const uid=post.uid const username=this.usersMap.get(uid).username if(!username){return "#"+this.getPostNumByPostId(id)} return username},getPostNumByPostId(id){const post=this.posts.find(post=>post.id===id) return post.num},getPostById(id){const post=this.posts.find(post=>post.id===id) return post},getPostByNum(num){const post=this.posts.find(post=>post.num===num) return post},getAvatarByUid(uid){const avatar=this.usersMap.get(uid)?.avatar if(!avatar){return this.getRandomAvatar()} return avatar},getAvatarByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post){return this.getRandomAvatar()} const uid=post.uid return this.getAvatarByUid(uid)},getRandomAvatar(){const num=Math.floor(Math.random()*100) return "https://randomuser.me/api/portraits/men/"+num+".jpg"},getUrlByUid(uid){const url=this.usersMap.get(uid)?.url if(!url){return ""} return url},getTextByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post||!post.content){return '点击跳转到#'+num+'查看'} const parser=new DOMParser() const doc=parser.parseFromString(post.content,'text/html') const text=doc.body.textContent||'' return text.slice(0,100)},addHeadingIds(){const content=document.getElementById('post-content-0') if(!content){this.nav.showTOC=false return} const headings=content.querySelectorAll('h2, h3, h4') headings.forEach((heading,index)=>{if(!heading.id){heading.id=`toc-nav-${index}`}}) if(headings.length==0){this.nav.showTOC=false}},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},debounce(fn,delay){let timer=null return function(...args){if(timer)clearTimeout(timer) timer=setTimeout(()=>{fn.apply(this,args)},delay);};},},watch:{'nav.post.targetPage':{handler:async function(newV,oldV){this.toPage()},immediate:false},},} const vuetify=createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")