flat: 性能优化,招聘会时间筛选性能优化、精选企业性能优化,封装缓存request、indexDb方法,主要用于不常更新的接口,以达到毫秒级性能
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
// BaseStore.js - 基础Store类
|
||||
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
|
||||
// import UniStorageHelper from '../common/UniStorageHelper'
|
||||
import useChatGroupDBStore from './userChatGroupStore'
|
||||
import config from '@/config'
|
||||
|
||||
|
||||
class BaseStore {
|
||||
db = null
|
||||
isDBReady = false
|
||||
dbName = 'BrowsingHistory'
|
||||
constructor() {
|
||||
this.checkAndInitDB()
|
||||
}
|
||||
checkAndInitDB() {
|
||||
// 获取本地数据库版本
|
||||
if (config.OnlyUseCachedDB) {
|
||||
return this.initDB()
|
||||
}
|
||||
const localVersion = uni.getStorageSync('indexedDBVersion') || 1
|
||||
console.log('DBVersion: ', localVersion, config.DBversion)
|
||||
if (localVersion === config.DBversion) {
|
||||
this.initDB()
|
||||
} else {
|
||||
console.log('清空本地数据库')
|
||||
this.clearDB().then(() => {
|
||||
uni.setStorageSync('indexedDBVersion', config.DBversion);
|
||||
this.initDB();
|
||||
});
|
||||
}
|
||||
}
|
||||
initDB() {
|
||||
// // #ifdef H5
|
||||
this.db = new IndexedDBHelper(this.dbName, config.DBversion);
|
||||
// // #endif
|
||||
// // #ifndef H5
|
||||
// this.db = new UniStorageHelper(this.dbName, config.DBversion);
|
||||
// // #endif
|
||||
this.db.openDB([{
|
||||
name: 'record',
|
||||
keyPath: "id",
|
||||
autoIncrement: true,
|
||||
}, {
|
||||
name: 'messageGroup',
|
||||
keyPath: "id",
|
||||
autoIncrement: true,
|
||||
}, {
|
||||
name: 'messages',
|
||||
keyPath: "id",
|
||||
autoIncrement: true,
|
||||
indexes: [{
|
||||
name: 'parentGroupId',
|
||||
key: 'parentGroupId',
|
||||
unique: false
|
||||
}]
|
||||
}]).then(async () => {
|
||||
useChatGroupDBStore().init()
|
||||
this.isDBReady = true
|
||||
});
|
||||
}
|
||||
async clearDB() {
|
||||
return new Promise((resolve, rejetc) => {
|
||||
new IndexedDBHelper().deleteDB(this.dbName).then(() => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const baseDB = new BaseStore()
|
||||
|
||||
export default baseDB
|
||||
@@ -9,7 +9,7 @@ import jobAnalyzer from '@/utils/jobAnalyzer';
|
||||
import {
|
||||
msg
|
||||
} from '@/common/globalFunction.js'
|
||||
import baseDB from './BaseDBStore';
|
||||
import baseDB from '@/utils/db.js';
|
||||
import config from '../config';
|
||||
|
||||
class JobRecommendation {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ref,
|
||||
toRaw
|
||||
} from 'vue'
|
||||
import baseDB from './BaseDBStore';
|
||||
import baseDB from '@/utils/db.js';
|
||||
import {
|
||||
msg,
|
||||
CloneDeep,
|
||||
|
||||
Reference in New Issue
Block a user