Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimiza el consumo de recursos mediante intervalos de guardado del storage de Baileys #1107

Open
wants to merge 1 commit into
base: builderbot
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions packages/provider-baileys/src/bailey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,32 @@ class BaileysProvider extends ProviderClass<WASocket> {
: bindStore({ logger: loggerBaileys })

if (this.store?.readFromFile) this.store?.readFromFile(`${NAME_DIR_SESSION}/baileys_store.json`)

setInterval(() => {

/*
Se crean dos intervalos para optimizar el uso del procesador y de la memoria RAM.
El primer intervalo verifica cada 10 segundos si los contactos ya se han registrado;
si no, los guarda y luego se cierra.
El segundo intervalo guarda los contactos cada 30 minutos.
*/
const path = `${NAME_DIR_SESSION}/baileys_store.json`
if (existsSync(NAME_DIR_SESSION)) {
this.store?.writeToFile(path)
const intervalId = setInterval(() => {

if (existsSync(NAME_DIR_SESSION)) {
this.store?.writeToFile(path)
if (this.store?.chats.all().length > 0)
{
clearInterval(intervalId);
}
}
}, 10_000)

setInterval(() => {
this.store.writeToFile(path);
}, 1_800_000);

if (this.globalVendorArgs.timeRelease > 0) {
await releaseTmp(NAME_DIR_SESSION, this.globalVendorArgs.timeRelease)
}
}, 10_000)

if (this.globalVendorArgs.timeRelease > 0) {
await releaseTmp(NAME_DIR_SESSION, this.globalVendorArgs.timeRelease)
}
}
} catch (e) {
logger.log(e)
Expand Down