Improve performance
This commit is contained in:
@@ -8,7 +8,8 @@ import { convertExternalLorebook } from "./lorebook.svelte"
|
||||
import { decodeRPack, encodeRPack } from "../rpack/rpack_bg"
|
||||
import { convertImage } from "../parser.svelte"
|
||||
import { Capacitor } from "@capacitor/core"
|
||||
import { DBState, HideIconStore, moduleBackgroundEmbedding } from "../stores.svelte"
|
||||
import { HideIconStore, moduleBackgroundEmbedding, ReloadGUIPointer } from "../stores.svelte"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
export interface RisuModule{
|
||||
name: string
|
||||
@@ -395,18 +396,18 @@ export async function applyModule() {
|
||||
alertNormal(language.successApplyModule)
|
||||
}
|
||||
|
||||
let lastGlobalEnabledModules: string[] = []
|
||||
let lastChatEnabledModules: string[] = []
|
||||
let lastModuleIds:string = ''
|
||||
|
||||
export function moduleUpdate(){
|
||||
if(!Array.isArray(lastGlobalEnabledModules)){
|
||||
lastGlobalEnabledModules = []
|
||||
}
|
||||
if(!Array.isArray(lastChatEnabledModules)){
|
||||
lastChatEnabledModules = []
|
||||
}
|
||||
|
||||
|
||||
const m = getModules()
|
||||
|
||||
const ids = m.map((m) => m.id).join('-')
|
||||
if(lastModuleIds !== ids){
|
||||
ReloadGUIPointer.set(get(ReloadGUIPointer) + 1)
|
||||
lastModuleIds = ids
|
||||
}
|
||||
|
||||
let moduleHideIcon = false
|
||||
let backgroundEmbedding = ''
|
||||
|
||||
@@ -65,9 +65,38 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
}
|
||||
|
||||
let bestMatchCache = new Map<string, string>()
|
||||
let processScriptCache = new Map<string, string>()
|
||||
|
||||
function cacheScript(scripts:customscript[], data:string, result:string){
|
||||
let hash = data + '|||'
|
||||
for(const script of scripts){
|
||||
hash += `${script.in}|||${script.out}|||${script.flag}|||${script.ableFlag}|||${script.type}`
|
||||
}
|
||||
|
||||
processScriptCache.set(hash, result)
|
||||
|
||||
}
|
||||
|
||||
function getScriptCache(scripts:customscript[], data:string){
|
||||
let hash = data + '|||'
|
||||
for(const script of scripts){
|
||||
hash += `${script.in}|||${script.out}|||${script.flag}|||${script.ableFlag}|||${script.type}`
|
||||
}
|
||||
|
||||
return processScriptCache.get(hash)
|
||||
}
|
||||
|
||||
export function resetScriptCache(){
|
||||
processScriptCache = new Map()
|
||||
}
|
||||
|
||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
||||
let db = getDatabase()
|
||||
const originalData = data
|
||||
const cached = getScriptCache((db.globalscript ?? []).concat(char.customscript), originalData)
|
||||
if(cached){
|
||||
return {data: cached, emoChanged: false}
|
||||
}
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
||||
data = await runCharacterJS({
|
||||
@@ -77,6 +106,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
})
|
||||
data = await runLuaEditTrigger(char, mode, data)
|
||||
if(scripts.length === 0){
|
||||
cacheScript(scripts, originalData, data)
|
||||
return {data, emoChanged}
|
||||
}
|
||||
function executeScript(pscript:pScript){
|
||||
@@ -311,6 +341,8 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
|
||||
}
|
||||
}
|
||||
|
||||
cacheScript(scripts, originalData, data)
|
||||
|
||||
return {data, emoChanged}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user