mirror of
https://github.com/SillyTavern/SillyTavern-Extras.git
synced 2026-04-30 03:11:26 +00:00
Debounce chat saving to 2 seconds
This commit is contained in:
@@ -24,9 +24,18 @@ function getStringHash(str, seed = 0) {
|
||||
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
||||
};
|
||||
|
||||
function debounce(func, timeout = 300) {
|
||||
let timer;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => { func.apply(this, args); }, timeout);
|
||||
};
|
||||
}
|
||||
|
||||
const getContext = () => window['TavernAI'].getContext();
|
||||
const getApiUrl = () => localStorage.getItem('extensions_url');
|
||||
const formatMemoryValue = (value) => value ? `[Context: "${value.trim()}"]` : '';
|
||||
const saveChatDebounced = debounce(() => getContext().saveChat(), 2000);
|
||||
|
||||
const defaultSettings = {
|
||||
minLongMemory: 16,
|
||||
@@ -325,7 +334,7 @@ function setMemoryContext(value, saveToMessage) {
|
||||
}
|
||||
|
||||
mes.extra.memory = value;
|
||||
context.saveChat();
|
||||
saveChatDebounced();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user