[feat] performace improvement stage 1
This commit is contained in:
@@ -197,7 +197,6 @@ export async function saveAsset(data:Uint8Array, customId:string = '', fileName:
|
||||
let form = `assets/${id}.${fileExtension}`
|
||||
const replacer = await forageStorage.setItem(form, data)
|
||||
if(replacer){
|
||||
console.log(replacer)
|
||||
return replacer
|
||||
}
|
||||
return form
|
||||
@@ -279,7 +278,6 @@ async function getDbBackups() {
|
||||
backups.push(parseInt(da))
|
||||
}
|
||||
}
|
||||
console.log(backups)
|
||||
while(backups.length > 20){
|
||||
const last = backups.pop()
|
||||
await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
|
||||
@@ -511,8 +509,6 @@ export async function globalFetch(url:string, arg:{
|
||||
|
||||
const urlHost = (new URL(url)).hostname
|
||||
let forcePlainFetch = (knownHostes.includes(urlHost) && (!isTauri)) || db.usePlainFetch || arg.plainFetchForce
|
||||
|
||||
console.log(urlHost)
|
||||
//check if the url is a local url like localhost
|
||||
if(urlHost.includes("localhost") || urlHost.includes("172.0.0.1") || urlHost.includes("0.0.0.0")){
|
||||
if((!isTauri) && (!isNodeServer)){
|
||||
@@ -704,7 +700,6 @@ export async function globalFetch(url:string, arg:{
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
return {
|
||||
ok:false,
|
||||
data: `${error}`,
|
||||
@@ -969,7 +964,6 @@ export function getRequestLog(){
|
||||
logString += `## ${log.date}\n\n* Request URL\n\n${b}${log.url}${bend}\n\n* Request Body\n\n${b}${log.body}${bend}\n\n* Request Header\n\n${b}${log.header}${bend}\n\n`
|
||||
+ `* Response Body\n\n${b}${log.response}${bend}\n\n* Response Success\n\n${b}${log.success}${bend}\n\n`
|
||||
}
|
||||
console.log(logString)
|
||||
return logString
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { writable } from "svelte/store";
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase } from "./storage/database";
|
||||
import { cloneDeep, isEqual } from "lodash";
|
||||
|
||||
function updateSize(){
|
||||
SizeStore.set({
|
||||
@@ -21,5 +23,82 @@ export const ViewBoxsize = writable({ width: 12 * 16, height: 12 * 16 }); // Def
|
||||
export const settingsOpen = writable(false)
|
||||
export const botMakerMode = writable(false)
|
||||
|
||||
//optimization
|
||||
|
||||
let db = get(DataBase)
|
||||
let currentChar = get(selectedCharID)
|
||||
let currentCharacter = db.characters ? (db.characters[currentChar]) : null
|
||||
let currentChat = currentCharacter ? (currentCharacter.chats[currentCharacter.chatPage]) : null
|
||||
export const CurrentCharacter = writable(cloneDeep(currentCharacter))
|
||||
export const CurrentChat = writable(cloneDeep(currentChat))
|
||||
|
||||
function updateCurrentCharacter(){
|
||||
const db = get(DataBase)
|
||||
if(!db.characters){
|
||||
CurrentCharacter.set(null)
|
||||
updateCurrentChat()
|
||||
return
|
||||
}
|
||||
|
||||
const currentCharId = get(selectedCharID)
|
||||
const currentChar = db.characters[currentCharId]
|
||||
const gotCharacter = get(CurrentCharacter)
|
||||
if(isEqual(gotCharacter, currentChar)){
|
||||
return
|
||||
}
|
||||
console.log("Character updated")
|
||||
CurrentCharacter.set(cloneDeep(currentChar))
|
||||
updateCurrentChat()
|
||||
}
|
||||
|
||||
function updateCurrentChat(){
|
||||
const currentChar = get(CurrentCharacter)
|
||||
if(!currentChar){
|
||||
CurrentChat.set(null)
|
||||
return
|
||||
}
|
||||
const chat = (currentChar.chats[currentChar.chatPage])
|
||||
const gotChat = get(CurrentChat)
|
||||
if(isEqual(gotChat, chat)){
|
||||
return
|
||||
}
|
||||
CurrentChat.set(cloneDeep(chat))
|
||||
}
|
||||
|
||||
DataBase.subscribe((data) => {
|
||||
updateCurrentCharacter()
|
||||
})
|
||||
|
||||
selectedCharID.subscribe((id) => {
|
||||
updateCurrentCharacter()
|
||||
})
|
||||
|
||||
CurrentCharacter.subscribe((char) => {
|
||||
updateCurrentChat()
|
||||
let db = get(DataBase)
|
||||
let charId = get(selectedCharID)
|
||||
if(charId === -1 || charId > db.characters.length){
|
||||
return
|
||||
}
|
||||
let cha = db.characters[charId]
|
||||
if(isEqual(cha, char)){
|
||||
return
|
||||
}
|
||||
db.characters[charId] = cloneDeep(char)
|
||||
DataBase.set(db)
|
||||
})
|
||||
|
||||
CurrentChat.subscribe((chat) => {
|
||||
let currentChar = get(CurrentCharacter)
|
||||
if(currentChar){
|
||||
if(isEqual(currentChar.chats[currentChar.chatPage], chat)){
|
||||
return
|
||||
}
|
||||
currentChar.chats[currentChar.chatPage] = cloneDeep(chat)
|
||||
CurrentCharacter.set(currentChar)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
updateSize()
|
||||
window.addEventListener("resize", updateSize);
|
||||
Reference in New Issue
Block a user