TryGhost / node-sqlite3

SQLite3 bindings for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The frequent insertion of electron using sqlite 3 causes the memory to soar

Quietly-20201113 opened this issue · comments

Issue Summary

I use sqlite 3 in electron, except for the initialization query, the rest has been doing data insertion operations, about a dozen per second, and then I also did a close, but the CPU memory will still soar over time

请问应该如何解决

 async insert(table_name,json){
        const {time, content } = json;
       
        this.db.serialize(() => {
          // this.db.run('BEGIN TRANSACTION');
          this.db.run(`INSERT INTO ${table_name} (time, content) VALUES (?, ?)`, [time, content], () => {
            this.close()
          });
          // this.db.run('COMMIT');
        });
       
    }

 
    async query(table_name,){
      return new Promise((resolve, reject) => {
        this.db.all(`SELECT * FROM ${table_name}`, async (err, rows) => {
            if (err) reject([]);
            resolve(rows);
         });
      })
   }

   close(){
    this.db && this.db.close(() => {
      this.db = null;
      this.db = new sqlite3.Database(this.path);
    });
   }

Steps to Reproduce

每秒插入十多条数据

Version

5.1.6

Node.js Version

v16.19.1

How did you install the library?

npm

sorry When sqlite executes the insert, I also push the new events event emitter message. Self-examination found that the memory soared because of the frequent message push