Move shallow toggle to config.yaml

3d813e4ef6e0d09998a55bf074c8d8d68fabfd4f

Cohee <18619528+Cohee1207@users.noreply.github.com>

7 files changed, +21 -24Showing whitespace changes
default/config.yaml+8 -2
@@ -1,8 +1,6 @@
11# -- DATA CONFIGURATION --
22# Root directory for user data storage
33dataRoot: ./data
4-# The maximum amount of memory that parsed character cards can use in MB
5-cardsCacheCapacity: 100
64# -- SERVER CONFIGURATION --
75# Listen for incoming connections
86listen: false
@@ -135,6 +133,14 @@ thumbnails:
135133 # Maximum thumbnail dimensions per type [width, height]
136134 dimensions: { 'bg': [160, 90], 'avatar': [96, 144] }
137135
136+# PERFORMANCE-RELATED CONFIGURATION
137+performance:
138+ # Enables lazy loading of character cards. Improves performances with large card libraries.
139+ # May have compatibility issues with some extensions.
140+ lazyLoadCharacters: false
141+ # The maximum amount of memory that parsed character cards can use in MB
142+ cardsCacheCapacity: 100
143+
138144# Allow secret keys exposure via API
139145allowKeysExposure: false
140146# Skip new default content checks
post-install.js+5 -0
@@ -96,6 +96,11 @@ const keyMigrationMap = [
9696 newKey: 'logging.minLogLevel',
9797 migrate: (value) => value,
9898 },
99+ {
100+ oldKey: 'cardsCacheCapacity',
101+ newKey: 'performance.cardsCacheCapacity',
102+ migrate: (value) => value,
103+ },
99104 // uncomment one release after 1.12.13
100105 /*
101106 {
public/index.html+0 -7
@@ -4424,13 +4424,6 @@
44244424 <option data-i18n="tag_import_existing" value="4">Existing</option>
44254425 </select>
44264426 </div>
4427- <label class="checkbox_label" for="shallow_characters" data-i18n="[title]Experimental feature. May behave unstable and have compatibility issues." title="Experimental feature. May behave unstable and have compatibility issues.">
4428- <input id="shallow_characters" type="checkbox" />
4429- <small data-i18n="Lazy Load Characters">
4430- Lazy Load Characters
4431- </small>
4432- <i class="fa-solid fa-flask"></i>
4433- </label>
44344427 <label class="checkbox_label" for="fuzzy_search_checkbox" title="Use fuzzy matching, and search characters in the list by all data fields, not just by a name substring." data-i18n="[title]Use fuzzy matching, and search characters in the list by all data fields, not just by a name substring">
44354428 <input id="fuzzy_search_checkbox" type="checkbox" />
44364429 <small data-i18n="Advanced Character Search">Advanced Character Search</small>
public/script.js+2 -3
@@ -1780,9 +1780,7 @@ export async function getCharacters() {
17801780 const response = await fetch('/api/characters/all', {
17811781 method: 'POST',
17821782 headers: getRequestHeaders(),
17831783 body: JSON.stringify({}),
1784- shallow: power_user.shallow_characters,
1785- }),
17861784 });
17871785 if (response.ok === true) {
17881786 characters.splice(0, characters.length);
@@ -6718,6 +6716,7 @@ export async function unshallowCharacter(characterId) {
67186716 return;
67196717 }
67206718
6719+ /** @type {import('./scripts/char-data.js').v1CharData} */
67216720 const character = characters[characterId];
67226721 if (!character) {
67236722 console.warn('Character not found:', characterId);
public/scripts/char-data.js+1 -0
@@ -113,5 +113,6 @@
113113 * @property {string} chat - name of the current chat file chat
114114 * @property {string} avatar - file name of the avatar image (acts as a unique identifier)
115115 * @property {string} json_data - the full raw JSON data of the character
116+ * @property {boolean?} shallow - if the data is shallow (lazy-loaded)
116117 */
117118export default 0;// now this file is a module
public/scripts/power-user.js+0 -8
@@ -314,7 +314,6 @@ let power_user = {
314314 forbid_external_media: true,
315315 external_media_allowed_overrides: [],
316316 external_media_forbidden_overrides: [],
317- shallow_characters: false,
318317};
319318
320319let themes = [];
@@ -1596,7 +1595,6 @@ async function loadPowerUserSettings(settings, data) {
15961595 $('#auto-connect-checkbox').prop('checked', power_user.auto_connect);
15971596 $('#auto-load-chat-checkbox').prop('checked', power_user.auto_load_chat);
15981597 $('#forbid_external_media').prop('checked', power_user.forbid_external_media);
1599- $('#shallow_characters').prop('checked', power_user.shallow_characters);
16001598
16011599 for (const theme of themes) {
16021600 const option = document.createElement('option');
@@ -3890,12 +3888,6 @@ $(document).ready(() => {
38903888 await exportTheme();
38913889 });
38923890
3893- $('#shallow_characters').on('input', function () {
3894- power_user.shallow_characters = !!$(this).prop('checked');
3895- saveSettingsDebounced();
3896- toastr.info('Reload the page for this setting to take effect');
3897- });
3898-
38993891 $(document).on('click', '#debug_table [data-debug-function]', function () {
39003892 const functionId = $(this).data('debug-function');
39013893 const functionRecord = debug_functions.find(f => f.functionId === functionId);
src/endpoints/characters.js+5 -4
@@ -24,11 +24,13 @@ import { importRisuSprites } from './sprites.js';
2424const defaultAvatarPath = './public/img/ai4.png';
2525
2626// KV-store for parsed character data
2727const cacheCapacity = Number(getConfigValue('performance.cardsCacheCapacity', 100, 'number')); // MB
2828// With 100 MB limit it would take roughly 3000 characters to reach this limit
2929const characterDataCache = new MemoryLimitedMap(1024 * 1024 * cacheCapacity);
3030// Some Android devices require tighter memory management
3131const isAndroid = process.platform === 'android';
32+// Use shallow character data for the character list
33+const useShallowCharacters = !!getConfigValue('performance.lazyLoadCharacters', false, 'boolean');
3234
3335/**
3436 * Reads the character card from the specified image file.
@@ -207,6 +209,7 @@ const calculateDataSize = (data) => {
207209 */
208210const toShallow = (character) => {
209211 return {
212+ shallow: true,
210213 name: character.name,
211214 avatar: character.avatar,
212215 chat: character.chat,
@@ -225,7 +228,6 @@ const toShallow = (character) => {
225228 fav: _.get(character, 'data.extensions.fav', false),
226229 },
227230 },
228- shallow: true,
229231 };
230232};
231233
@@ -1022,10 +1024,9 @@ router.post('/delete', jsonParser, validateAvatarUrlMiddleware, async function (
10221024 */
10231025router.post('/all', jsonParser, async function (request, response) {
10241026 try {
1025- const shallow = !!request.body.shallow;
10261027 const files = fs.readdirSync(request.user.directories.characters);
10271028 const pngFiles = files.filter(file => file.endsWith('.png'));
10281029 const processingPromises = pngFiles.map(file => processCharacter(file, request.user.directories, { shallow: useShallowCharacters }));
10291030 const data = (await Promise.all(processingPromises)).filter(c => c.name);
10301031 return response.send(data);
10311032 } catch (err) {