feat: CombManager缓存
This commit is contained in:
parent
10325df72d
commit
5b617a67d5
|
@ -14,23 +14,26 @@ struct Index {
|
|||
async aboutToAppear() {
|
||||
const ver = await CombNetTools.getVer()
|
||||
console.log(this.TAG, 'ver', JSON.stringify(ver))
|
||||
const cfg = await CombNetTools.getConfigFile(ver?.full_url ?? '')
|
||||
console.log(this.TAG, 'full_config', JSON.stringify(cfg))
|
||||
const cfg = await CombNetTools.getConfigFile(ver?.diff_url ?? '')
|
||||
if (cfg) {
|
||||
console.log(this.TAG, 'full_config', 'cfg', JSON.stringify(cfg.data))
|
||||
console.log(this.TAG, 'full_config', 'etag', JSON.stringify(cfg.etag))
|
||||
}
|
||||
|
||||
// KOnlineParamsUtil.init(getContext())
|
||||
// KOnlineParamsUtil.requestAsync()
|
||||
// KOnlineParamsUtil.run()
|
||||
//
|
||||
// let time = 1
|
||||
// KOnlineParamsManager.getInstance().registerOnParamsChangeListener(() => {
|
||||
// console.log(this.TAG, 'CombData is changed! times: ' + time++);
|
||||
// })
|
||||
KOnlineParamsUtil.init(getContext())
|
||||
KOnlineParamsUtil.requestAsync() // 首次启动拉取数据
|
||||
KOnlineParamsUtil.run()
|
||||
|
||||
let time = 1
|
||||
KOnlineParamsManager.registerOnParamsChangeListener(() => {
|
||||
console.log(this.TAG, 'CombData is changed! times: ' + time++);
|
||||
})
|
||||
}
|
||||
|
||||
async getModule(id: string) {
|
||||
const begin = Date.now()
|
||||
|
||||
const modules = await KOnlineParamsManager.getInstance().getProjectConfig().getMaxPriorityModuleFromMG(id)
|
||||
const modules = await KOnlineParamsManager.getParams(id)
|
||||
if (!modules) return 'not found'
|
||||
|
||||
console.log(this.TAG, `${modules.getAllParams().length}`);
|
||||
|
@ -75,9 +78,7 @@ struct Index {
|
|||
TextInput({ placeholder: 'input' }).width(200).onChange(value => this.key1 = value)
|
||||
Text(this.value1 === '' ? 'test' : this.value1).width(200)
|
||||
Button("get").onClick(async () => {
|
||||
const mParams = await KOnlineParamsManager.getInstance()
|
||||
.getProjectConfig()
|
||||
.getMaxPriorityModuleFromMG(this.input)
|
||||
const mParams = await KOnlineParamsManager.getParams(this.input)
|
||||
if (mParams) {
|
||||
this.value1 = String(mParams.getValue(this.key1, ''))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { CombConfigManager } from './comb/CombConfigManager'
|
||||
import { KParams } from './comb/KParams'
|
||||
import { HashMap } from '@kit.ArkTS'
|
||||
|
||||
export type OnParamsChangeListener = () => void
|
||||
|
||||
|
@ -28,13 +27,19 @@ export class KOnlineParamsManager {
|
|||
this.combConfigManager = combConfigManager
|
||||
}
|
||||
|
||||
getProjectConfig(): KParams.ProjectParams {
|
||||
private getProjectConfig(): KParams.ProjectParams {
|
||||
if (!this.combConfigManager) {
|
||||
throw new Error('KOnlineParamsManager not initialized')
|
||||
}
|
||||
return this.combConfigManager.getProjectConfig()
|
||||
}
|
||||
|
||||
static async getParams(groupId: string) {
|
||||
return await KOnlineParamsManager.getInstance()
|
||||
.getProjectConfig()
|
||||
.getMaxPriorityModuleFromMG(groupId)
|
||||
}
|
||||
|
||||
// 强制拉取
|
||||
async requestForce(isDiff: boolean = false) {
|
||||
await this.combConfigManager?.requestUpdateAsync(isDiff)
|
||||
|
@ -50,15 +55,15 @@ export class KOnlineParamsManager {
|
|||
this.combConfigManager?.stop()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册comb更新监听器
|
||||
*/
|
||||
registerOnParamsChangeListener(onParamsChangeListener: OnParamsChangeListener): string {
|
||||
return this.combConfigManager?.registerOnDataChangeListener(onParamsChangeListener) ?? ''
|
||||
static registerOnParamsChangeListener(onParamsChangeListener: OnParamsChangeListener): string {
|
||||
return KOnlineParamsManager.getInstance()
|
||||
.combConfigManager?.registerOnDataChangeListener(onParamsChangeListener) ?? ''
|
||||
}
|
||||
|
||||
unregisterOnParamsChangeListener(id: string) {
|
||||
this.combConfigManager?.unregisterOnDataChangeListener(id)
|
||||
static unregisterOnParamsChangeListener(id: string) {
|
||||
KOnlineParamsManager.getInstance().combConfigManager?.unregisterOnDataChangeListener(id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { CombDataUpdater } from '../comb_base/CombDataUpdater'
|
|||
import { CombDataStore } from '../comb_store/CombDataStore'
|
||||
import { PreferencesStoreCore } from '../comb_store/core/PreferencesStoreCore'
|
||||
import { CombConfigManager } from './CombConfigManager'
|
||||
import { HashMap } from '@kit.ArkTS'
|
||||
|
||||
/**
|
||||
* 多个蜂巢工程管理类
|
||||
|
@ -12,30 +13,36 @@ import { CombConfigManager } from './CombConfigManager'
|
|||
*/
|
||||
export class CombManager {
|
||||
private context: Context
|
||||
private combMap: HashMap<number, CombConfigManager>
|
||||
|
||||
constructor(ctx: Context) {
|
||||
this.context = ctx
|
||||
this.combMap = new HashMap()
|
||||
}
|
||||
|
||||
getCombConfigManager(projectID: number = 0) {
|
||||
const storeCore = new PreferencesStoreCore(this.context)
|
||||
const combStore = new CombDataStore(this.context, storeCore)
|
||||
const combParser = new CombDataParser()
|
||||
const combChecker = new CombDataChecker()
|
||||
const combObserver = new CombDataObserver()
|
||||
getCombConfigManager(projectID: number = -1) {
|
||||
let combConfigManager = this.combMap.get(projectID)
|
||||
if (combConfigManager) return combConfigManager
|
||||
|
||||
const storeCore = new PreferencesStoreCore(this.context) // 存储引擎
|
||||
const combStore = new CombDataStore({ core: storeCore }) // 本地缓存仓库
|
||||
const combParser = new CombDataParser() // 数据解析器
|
||||
const combChecker = new CombDataChecker() // 数据校验器
|
||||
const combObserver = new CombDataObserver() // 发布订阅器
|
||||
const combUpdater = new CombDataUpdater({
|
||||
store: combStore,
|
||||
parser: combParser,
|
||||
checker: combChecker,
|
||||
observer: combObserver,
|
||||
})
|
||||
}) // 数据更新器
|
||||
|
||||
const combConfigManager = new CombConfigManager({
|
||||
combConfigManager = new CombConfigManager({
|
||||
store: combStore,
|
||||
updater: combUpdater,
|
||||
observer: combObserver,
|
||||
})
|
||||
|
||||
this.combMap.set(projectID, combConfigManager)
|
||||
return combConfigManager
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,10 @@ export class CombDataUpdater implements ICombUpdater {
|
|||
}
|
||||
|
||||
async getVer() {
|
||||
const verData = await CombNetTools.getVer()
|
||||
const localVerion = await this.dataStore.getVersion()
|
||||
const verData = await CombNetTools.getVer() // 传递版本号
|
||||
this.verData = verData
|
||||
return verData
|
||||
|
||||
}
|
||||
|
||||
async update(isDiff: boolean = false) {
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
export namespace CombConfigManager {
|
||||
}
|
|
@ -1,18 +1,22 @@
|
|||
import { IConfigFileRes, IVerData } from '../comb_type/CombTypes'
|
||||
import { android_comb_diff_cofig, android_comb_full_config } from '../data/androd_comb_config'
|
||||
import { CombNetUtil } from '../comb_utils/CombNetUtil'
|
||||
import { CipherUtil } from '../comb_utils/CipherUtil'
|
||||
import { CompressUtil } from '../comb_utils/CompressUtil'
|
||||
|
||||
export namespace CombNetTools {
|
||||
const projectId = 1
|
||||
|
||||
const BASE_URL = `honeycomb.wps.cn/api/v4/project/${projectId}`
|
||||
const VER_URL = BASE_URL + '/ver'
|
||||
const IDS_URL = BASE_URL + '/ids'
|
||||
|
||||
const projectid = 1
|
||||
const ver = 2700
|
||||
const skv = 1665471000
|
||||
|
||||
const iv = 'aacbcb1b3299ff61'
|
||||
const key = '44d81af4045343d3'
|
||||
|
||||
|
||||
async function deData(data: Uint8Array) {
|
||||
const key_ = await CipherUtil.generateKey(128, key)
|
||||
const data_decrypted = await CipherUtil.decrypt(data, key_, 128)
|
||||
|
@ -29,7 +33,7 @@ export namespace CombNetTools {
|
|||
// headers: {Client-Type: wps-android; Client-Ver: 1; Client-Chann: 1;}
|
||||
|
||||
try {
|
||||
const res = await CombNetUtil.getVer(projectid, ver, skv)
|
||||
const res = await CombNetUtil.getVer(projectId, ver, skv)
|
||||
return res
|
||||
} catch (e) {
|
||||
return
|
||||
|
|
|
@ -16,17 +16,19 @@ import { HashMap } from '@kit.ArkTS'
|
|||
import { IDiffConfigFile, IFullConfigFile } from '../comb_type/CombTypes'
|
||||
import { KLog } from '../comb_utils/KLog'
|
||||
|
||||
interface ICombDataProps {
|
||||
core: ICombStoreCore
|
||||
}
|
||||
|
||||
export class CombDataStore {
|
||||
private TAG: string = 'CombDataStore'
|
||||
public storeCore: ICombStoreCore
|
||||
private ctx: Context
|
||||
private moduleMap: HashMap<string, KModule>
|
||||
private static LATEST_REQUEST_TIME_STAMP: string = 'latest_request_time_stamp'
|
||||
private static DELAY_UPDATE_TIME: string = 'delay_update_time'
|
||||
|
||||
constructor(ctx: Context, storeCore: ICombStoreCore) {
|
||||
this.ctx = ctx
|
||||
this.storeCore = storeCore
|
||||
constructor(props: ICombDataProps) {
|
||||
this.storeCore = props.core
|
||||
this.moduleMap = new HashMap()
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,12 @@ export interface IDiffModules {
|
|||
}
|
||||
|
||||
|
||||
export interface IVerResponse {
|
||||
code?: number
|
||||
msg?: string
|
||||
data?: IVerData
|
||||
}
|
||||
|
||||
export interface IVerData {
|
||||
ver: number
|
||||
full_url: string
|
||||
|
|
Loading…
Reference in New Issue
Block a user