Change DataBase inside svelte to DBState for performance

This commit is contained in:
kwaroran
2024-10-23 23:46:32 +09:00
parent a9f1819044
commit 2044d9b63b
122 changed files with 1372 additions and 1424 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from 'svelte';
import { DataBase } from "../../../ts/storage/database";
import { DBState } from "../../../ts/storage/database.svelte";
import { longpress } from 'src/ts/gui/longtouch';
let textarea:HTMLElement = $state();
@@ -35,6 +35,6 @@
use:longpress={handleLongPress}
bind:value={value}
class="rounded-md p-2 text-textcolor bg-transparent resize-none overflow-y-hidden border border-darkborderc"
style:font-size="{0.875 * ($DataBase.zoomsize / 100)}rem"
style:line-height="{($DataBase.lineHeight ?? 1.25) * ($DataBase.zoomsize / 100)}rem"
style:font-size="{0.875 * (DBState.db.zoomsize / 100)}rem"
style:line-height="{(DBState.db.lineHeight ?? 1.25) * (DBState.db.zoomsize / 100)}rem"
></textarea>

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { DataBase, appVer, webAppSubVer } from "src/ts/storage/database";
import { DBState, appVer, webAppSubVer } from "src/ts/storage/database.svelte";
import Hub from "./Realm/RealmMain.svelte";
import { OpenRealmStore } from "src/ts/stores";
import { ArrowLeft } from "lucide-svelte";
@@ -25,7 +25,7 @@
<h1 class="text-2xl font-bold">Recently Uploaded<button class="text-base font-medium float-right p-1 bg-darkbg rounded-md hover:ring" onclick={() => {
$OpenRealmStore = true
}}>Get More</button></h1>
{#if !$DataBase.hideRealm}
{#if !DBState.db.hideRealm}
{#await getRisuHub({
search: '',
page: 0,

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { DataBase } from "src/ts/storage/database";
import { DBState } from "src/ts/storage/database.svelte";
import { getHordeModels } from "src/ts/horde/getModels";
import Arcodion from "./Arcodion.svelte";
import { language } from "src/lang";
@@ -89,7 +89,7 @@
{/if}
</Arcodion>
<button class="hover:bg-selected px-6 py-2 text-lg" onclick={() => {changeModel('reverse_proxy')}}>Custom (OpenAI-compatible)</button>
{#if $DataBase.tpo && isTauri}
{#if DBState.db.tpo && isTauri}
<button class="hover:bg-selected px-6 py-2 text-lg" onclick={async () => {
const selected = await open({
filters: [{
@@ -178,7 +178,7 @@
</Arcodion>
<button class="hover:bg-selected px-6 py-2 text-lg" onclick={() => {changeModel('risullm-proto')}}>RisuAI LLM (Prototype)</button>
{/if}
{#if $DataBase.plugins.length > 0}
{#if DBState.db.plugins.length > 0}
<button onclick={() => {changeModel('custom')}} class="hover:bg-selected px-6 py-2 text-lg" >Plugin</button>
{/if}
<div class="text-textcolor2 text-xs">

View File

@@ -8,7 +8,7 @@
import CheckInput from "./GUI/CheckInput.svelte";
import { ArrowDown, ArrowUp, XIcon } from "lucide-svelte";
import TextInput from "./GUI/TextInput.svelte";
import { DataBase } from "src/ts/storage/database";
import { DBState } from "src/ts/storage/database.svelte";
interface Props {
promptItem: PromptItem;
onRemove?: () => void;
@@ -64,7 +64,7 @@
<OptionInput value="lorebook">{language.formating.lorebook}</OptionInput>
<OptionInput value="memory">{language.formating.memory}</OptionInput>
<OptionInput value="postEverything">{language.formating.postEverything}</OptionInput>
{#if $DataBase.promptSettings.customChainOfThought}
{#if DBState.db.promptSettings.customChainOfThought}
<OptionInput value="cot">{language.cot}</OptionInput>
{/if}
</SelectInput>
@@ -105,7 +105,7 @@
}
}} />
{/if}
{#if $DataBase.promptSettings.sendChatAsSystem}
{#if DBState.db.promptSettings.sendChatAsSystem}
<CheckInput name={language.chatAsOriginalOnSystem} bind:check={promptItem.chatAsOriginalOnSystem}/>
{/if}
{/if}

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { alertMd } from "src/ts/alert";
import { shareRealmCardData } from "src/ts/realm";
import { DataBase, downloadPreset } from "src/ts/storage/database";
import { DBState, downloadPreset } from "src/ts/storage/database.svelte";
import { selectedCharID, ShowRealmFrameStore } from "src/ts/stores";
import { sleep } from "src/ts/util";
import { onDestroy, onMount } from "svelte";
@@ -10,8 +10,8 @@
$ShowRealmFrameStore = ''
}
let iframe: HTMLIFrameElement = $state(null)
const tk = $DataBase?.account?.token;
const id = $DataBase?.account?.id
const tk = DBState.db?.account?.token;
const id = DBState.db?.account?.id
let loadingStage = $state(0)
let pongGot = false
@@ -30,9 +30,9 @@
if($ShowRealmFrameStore.startsWith('preset') || $ShowRealmFrameStore.startsWith('module')){
//TODO, add preset edit
}
else if($DataBase.characters[$selectedCharID].type === 'character'){
else if(DBState.db.characters[$selectedCharID].type === 'character'){
loadingStage = 0
$DataBase.characters[$selectedCharID].realmId = e.data.id
DBState.db.characters[$selectedCharID].realmId = e.data.id
}
close()
}
@@ -67,7 +67,7 @@
}
}
else if($ShowRealmFrameStore.startsWith('module')){
const predata = $DataBase.modules[Number($ShowRealmFrameStore.split(':')[1])]
const predata = DBState.db.modules[Number($ShowRealmFrameStore.split(':')[1])]
//@ts-ignore
predata.type = 'risuModule'
const encodedPredata = new TextEncoder().encode(JSON.stringify(predata))
@@ -96,8 +96,8 @@
if($ShowRealmFrameStore.startsWith('preset') || $ShowRealmFrameStore.startsWith('module')){
//TODO, add preset edit
}
else if($DataBase.characters[$selectedCharID].type === 'character' && $DataBase.characters[$selectedCharID].realmId){
url += `&edit=${$DataBase.characters[$selectedCharID].realmId}&edit-type=normal`
else if(DBState.db.characters[$selectedCharID].type === 'character' && DBState.db.characters[$selectedCharID].realmId){
url += `&edit=${DBState.db.characters[$selectedCharID].realmId}&edit-type=normal`
}
url += '#noLayout'
return url

View File

@@ -3,7 +3,7 @@
import { language } from "src/lang";
import { alertConfirm, alertInput, alertNormal } from "src/ts/alert";
import { hubURL, type hubType, downloadRisuHub, getRealmInfo } from "src/ts/characterCards";
import { DataBase } from "src/ts/storage/database";
import { DBState } from "src/ts/storage/database.svelte";
import RealmLicense from "./RealmLicense.svelte";
import MultiLangDisplay from "../GUI/MultiLangDisplay.svelte";
import { tooltip } from "src/ts/gui/tooltip";
@@ -86,7 +86,7 @@
})}>
<FlagIcon />
</button>
{#if ($DataBase.account?.token?.split('-') ?? [])[1] === openedData.creator}
{#if (DBState.db.account?.token?.split('-') ?? [])[1] === openedData.creator}
<button class="text-textcolor2 hover:text-red-500" onclick={(async (e) => {
e.stopPropagation()
const conf = await alertConfirm('Do you want to remove this character from Realm?')
@@ -95,7 +95,7 @@
method: "POST",
body: JSON.stringify({
id: openedData.id,
token: $DataBase.account?.token
token: DBState.db.account?.token
})
})
alertNormal(await da.text())

View File

@@ -5,7 +5,7 @@
onclick?.(e)
}}>
{#if !$DataBase.account}
{#if !DBState.db.account}
<span class="font-bold text-2xl w-full">You must login to Risu Account upload to RisuRealm</span>
<span class="text-textcolor2">You can login in app settings 🡲 account</span>
<button onclick={async () => {
@@ -111,7 +111,7 @@
import { language } from "src/lang";
import { alertError } from "src/ts/alert";
import { shareRisuHub2 } from "src/ts/characterCards";
import { DataBase, type character } from "src/ts/storage/database";
import { DBState, type character } from "src/ts/storage/database.svelte";
import TextInput from "../GUI/TextInput.svelte";
import Button from "../GUI/Button.svelte";
import SelectInput from "../GUI/SelectInput.svelte";

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { alertMd, alertNormal } from "src/ts/alert";
import { DataBase } from "src/ts/storage/database";
import { alertMd } from "src/ts/alert";
import { DBState } from "src/ts/storage/database.svelte";
import { openURL } from "src/ts/storage/globalApi";
import { sideBarStore } from "src/ts/stores";
@@ -22,10 +22,10 @@
specialDay = 'halloween'
}
if( (today.getMonth() === 8 && today.getDate() === 16)){
if($DataBase.language === 'ko'){
if(DBState.db.language === 'ko'){
specialDay = 'chuseok'
}
else if($DataBase.language === 'zh-Hant' || $DataBase.language === 'zh'){
else if(DBState.db.language === 'zh-Hant' || DBState.db.language === 'zh'){
specialDay = 'midAutumn'
}
}
@@ -37,7 +37,7 @@
const onClick = () => {
if(specialDay === 'newYear'){
const db = $DataBase
const db = DBState.db
let messages = 0
let chats = 0
if(db.statistics?.newYear2024){