[ref] performace improvement stage 2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { ArrowLeft, ArrowRight, EditIcon, LanguagesIcon, RefreshCcwIcon, TrashIcon, CopyIcon } from "lucide-svelte";
|
||||
import { ParseMarkdown } from "../../ts/parser";
|
||||
import { ParseMarkdown, type simpleCharacterArgument } from "../../ts/parser";
|
||||
import AutoresizeArea from "../UI/GUI/TextAreaResizable.svelte";
|
||||
import { alertConfirm } from "../../ts/alert";
|
||||
import { language } from "../../lang";
|
||||
@@ -16,7 +16,7 @@
|
||||
export let rerollIcon = false
|
||||
export let onReroll = () => {}
|
||||
export let unReroll = () => {}
|
||||
export let character:character|groupChat|null = null
|
||||
export let character:simpleCharacterArgument|string|null = null
|
||||
let translating = false
|
||||
let editMode = false
|
||||
let statusMessage:string = ''
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Suggestion from './Suggestion.svelte';
|
||||
import { CameraIcon, DatabaseIcon, DicesIcon, GlobeIcon, LanguagesIcon, Laugh, MenuIcon, MicOffIcon, RefreshCcwIcon, ReplyIcon, Send } from "lucide-svelte";
|
||||
import { CurrentCharacter, CurrentChat, selectedCharID } from "../../ts/stores";
|
||||
import { CurrentCharacter, CurrentChat, CurrentUsername, selectedCharID, CurrentUserIcon, CurrentShowMemoryLimit,CurrentSimpleCharacter } from "../../ts/stores";
|
||||
import Chat from "./Chat.svelte";
|
||||
import { DataBase, type Message, type character, type groupChat } from "../../ts/storage/database";
|
||||
import { getCharImage } from "../../ts/characters";
|
||||
@@ -420,8 +420,8 @@
|
||||
rerollIcon={i === 0}
|
||||
onReroll={reroll}
|
||||
unReroll={unReroll}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||
character={$CurrentCharacter}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $CurrentShowMemoryLimit}
|
||||
character={$CurrentSimpleCharacter}
|
||||
/>
|
||||
{:else}
|
||||
<Chat
|
||||
@@ -432,25 +432,25 @@
|
||||
onReroll={reroll}
|
||||
unReroll={unReroll}
|
||||
img={getCharImage(findCharacterbyId(chat.saying).image, 'css')}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||
character={findCharacterbyId(chat.saying)}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $CurrentShowMemoryLimit}
|
||||
character={chat.saying}
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<Chat
|
||||
character={$CurrentCharacter}
|
||||
character={$CurrentSimpleCharacter}
|
||||
idx={chat.index}
|
||||
name={$DataBase.username}
|
||||
name={$CurrentUsername}
|
||||
message={chat.data}
|
||||
img={getCharImage($DataBase.userIcon, 'css')}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $DataBase.showMemoryLimit}
|
||||
img={getCharImage($CurrentUserIcon, 'css')}
|
||||
isLastMemory={$CurrentChat.lastMemory === (chat.chatId ?? 'none') && $CurrentShowMemoryLimit}
|
||||
/>
|
||||
{/if}
|
||||
{/each}
|
||||
{#if $CurrentChat.message.length <= loadPages}
|
||||
{#if $CurrentCharacter.type !== 'group'}
|
||||
<Chat
|
||||
character={$CurrentCharacter}
|
||||
character={$CurrentSimpleCharacter}
|
||||
name={$CurrentCharacter.name}
|
||||
message={$CurrentCharacter.firstMsgIndex === -1 ? $CurrentCharacter.firstMessage :
|
||||
$CurrentCharacter.alternateGreetings[$CurrentCharacter.firstMsgIndex]}
|
||||
|
||||
@@ -2,7 +2,7 @@ import DOMPurify from 'isomorphic-dompurify';
|
||||
import showdown from 'showdown';
|
||||
import { Marked } from 'marked';
|
||||
|
||||
import { DataBase, type Database, type Message, type character, type groupChat } from './storage/database';
|
||||
import { DataBase, type Database, type Message, type character, type customscript, type groupChat } from './storage/database';
|
||||
import { getFileSrc } from './storage/globalApi';
|
||||
import { processScript, processScriptFull } from './process/scripts';
|
||||
import { get } from 'svelte/store';
|
||||
@@ -58,7 +58,7 @@ DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
|
||||
|
||||
const assetRegex = /{{(raw|img|video|audio|bg)::(.+?)}}/g
|
||||
|
||||
async function parseAdditionalAssets(data:string, char:character, mode:'normal'|'back'){
|
||||
async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back'){
|
||||
const db = get(DataBase)
|
||||
const assetWidthString = (db.assetWidth && db.assetWidth !== -1 || db.assetWidth === 0) ? `max-width:${db.assetWidth}rem;` : ''
|
||||
|
||||
@@ -97,9 +97,19 @@ async function parseAdditionalAssets(data:string, char:character, mode:'normal'|
|
||||
return data
|
||||
}
|
||||
|
||||
export async function ParseMarkdown(data:string, char:(character | groupChat) = null, mode:'normal'|'back' = 'normal', chatID=-1) {
|
||||
export interface simpleCharacterArgument{
|
||||
type: 'simple'
|
||||
additionalAssets?: [string, string, string][]
|
||||
customscript: customscript[]
|
||||
chaId: string,
|
||||
}
|
||||
|
||||
|
||||
export async function ParseMarkdown(data:string, charArg:(simpleCharacterArgument | groupChat | string) = null, mode:'normal'|'back' = 'normal', chatID=-1) {
|
||||
let firstParsed = ''
|
||||
const orgDat = data
|
||||
|
||||
let char = (typeof(charArg) === 'string') ? (findCharacterbyId(charArg)) : (charArg)
|
||||
if(char && char.type !== 'group'){
|
||||
data = await parseAdditionalAssets(data, char, mode)
|
||||
firstParsed = data
|
||||
|
||||
@@ -5,7 +5,7 @@ import { downloadFile } from "../storage/globalApi";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { selectSingleFile } from "../util";
|
||||
import { risuChatParser as risuChatParserOrg } from "../parser";
|
||||
import { risuChatParser as risuChatParserOrg, type simpleCharacterArgument } from "../parser";
|
||||
import { autoMarkPlugin } from "../plugins/automark";
|
||||
|
||||
const dreg = /{{data}}/g
|
||||
@@ -54,7 +54,7 @@ export async function importRegex(){
|
||||
}
|
||||
}
|
||||
|
||||
export function processScriptFull(char:character|groupChat, data:string, mode:ScriptMode, chatID = -1){
|
||||
export function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1){
|
||||
let db = get(DataBase)
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript)
|
||||
@@ -83,14 +83,16 @@ export function processScriptFull(char:character|groupChat, data:string, mode:Sc
|
||||
if(tempEmotion.length > 4){
|
||||
tempEmotion.splice(0, 1)
|
||||
}
|
||||
for(const emo of char.emotionImages){
|
||||
if(emo[0] === emoName){
|
||||
const emos:[string, string,number] = [emo[0], emo[1], Date.now()]
|
||||
tempEmotion.push(emos)
|
||||
charemotions[char.chaId] = tempEmotion
|
||||
CharEmotion.set(charemotions)
|
||||
emoChanged = true
|
||||
break
|
||||
if(char.type !== 'simple'){
|
||||
for(const emo of char.emotionImages){
|
||||
if(emo[0] === emoName){
|
||||
const emos:[string, string,number] = [emo[0], emo[1], Date.now()]
|
||||
tempEmotion.push(emos)
|
||||
charemotions[char.chaId] = tempEmotion
|
||||
CharEmotion.set(charemotions)
|
||||
emoChanged = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase } from "./storage/database";
|
||||
import { DataBase, type character, type groupChat } from "./storage/database";
|
||||
import { cloneDeep, isEqual } from "lodash";
|
||||
import type { simpleCharacterArgument } from "./parser";
|
||||
|
||||
function updateSize(){
|
||||
SizeStore.set({
|
||||
@@ -30,7 +31,28 @@ 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 CurrentSimpleCharacter = writable(createSimpleCharacter(currentCharacter))
|
||||
export const CurrentChat = writable(cloneDeep(currentChat))
|
||||
export const CurrentUsername = writable(db.username)
|
||||
export const CurrentUserIcon = writable(db.userIcon)
|
||||
export const CurrentShowMemoryLimit = writable(db.showMemoryLimit)
|
||||
|
||||
function createSimpleCharacter(char:character|groupChat){
|
||||
if((!char) || char.type === 'group'){
|
||||
return null
|
||||
}
|
||||
|
||||
const simpleChar:simpleCharacterArgument = {
|
||||
type: "simple",
|
||||
customscript: cloneDeep(char.customscript),
|
||||
chaId: char.chaId,
|
||||
additionalAssets: char.additionalAssets
|
||||
}
|
||||
|
||||
return simpleChar
|
||||
|
||||
}
|
||||
|
||||
|
||||
function updateCurrentCharacter(){
|
||||
const db = get(DataBase)
|
||||
@@ -48,6 +70,12 @@ function updateCurrentCharacter(){
|
||||
}
|
||||
console.log("Character updated")
|
||||
CurrentCharacter.set(cloneDeep(currentChar))
|
||||
const simp = createSimpleCharacter(currentChar)
|
||||
|
||||
if(!isEqual(get(CurrentSimpleCharacter), simp)){
|
||||
CurrentSimpleCharacter.set(simp)
|
||||
}
|
||||
|
||||
updateCurrentChat()
|
||||
}
|
||||
|
||||
@@ -67,6 +95,15 @@ function updateCurrentChat(){
|
||||
|
||||
DataBase.subscribe((data) => {
|
||||
updateCurrentCharacter()
|
||||
if(data.username !== get(CurrentUsername)){
|
||||
CurrentUsername.set(data.username)
|
||||
}
|
||||
if(data.userIcon !== get(CurrentUserIcon)){
|
||||
CurrentUserIcon.set(data.userIcon)
|
||||
}
|
||||
if(data.showMemoryLimit !== get(CurrentShowMemoryLimit)){
|
||||
CurrentShowMemoryLimit.set(data.showMemoryLimit)
|
||||
}
|
||||
})
|
||||
|
||||
selectedCharID.subscribe((id) => {
|
||||
|
||||
Reference in New Issue
Block a user