Skip to content

Commit

Permalink
fix: resolve LRU conflicts, cache loss and premature engine breaking …
Browse files Browse the repository at this point in the history
…change (#2988)

* fix: resolve LRU conflicts and unintentional engine breaking change

* chore: update lru.min

* chore: update lru.min

* chore: update lru.min

* chore: update lru.min
  • Loading branch information
wellwelwel authored Sep 11, 2024
1 parent 0b01333 commit 2c3c858
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
8 changes: 4 additions & 4 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const EventEmitter = require('events').EventEmitter;
const Readable = require('stream').Readable;
const Queue = require('denque');
const SqlString = require('sqlstring');
const LRU = require('lru-cache').default;
const { createLRU } = require('lru.min');

const PacketParser = require('./packet_parser.js');
const Packets = require('./packets/index.js');
Expand Down Expand Up @@ -75,9 +75,9 @@ class Connection extends EventEmitter {
this._command = null;
this._paused = false;
this._paused_packets = new Queue();
this._statements = new LRU({
this._statements = createLRU({
max: this.config.maxPreparedStatements,
dispose: function(statement) {
onEviction: function(_, statement) {
statement.close();
}
});
Expand Down Expand Up @@ -411,7 +411,7 @@ class Connection extends EventEmitter {
err.code = code || 'PROTOCOL_ERROR';
this.emit('error', err);
}

get fatalError() {
return this._fatalError;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/parsers/parser_cache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const LRU = require('lru-cache').default;
const { createLRU } = require('lru.min');

let parserCache = new LRU({
const parserCache = createLRU({
max: 15000,
});

Expand Down Expand Up @@ -51,7 +51,7 @@ function getParser(type, fields, options, config, compiler) {
}

function setMaxCache(max) {
parserCache = new LRU({ max });
parserCache.resize(max);
}

function clearCache() {
Expand Down
4 changes: 2 additions & 2 deletions lib/parsers/string.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const Iconv = require('iconv-lite');
const LRU = require('lru-cache').default;
const { createLRU } = require('lru.min');

const decoderCache = new LRU({
const decoderCache = createLRU({
max: 500,
});

Expand Down
27 changes: 17 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.3",
"long": "^5.2.1",
"lru-cache": "^8.0.0",
"lru.min": "^1.0.0",
"named-placeholders": "^1.1.3",
"seq-queue": "^0.0.5",
"sqlstring": "^2.3.2"
Expand Down

0 comments on commit 2c3c858

Please sign in to comment.