Skip to content

Commit

Permalink
[CONJS-219] prepare cache doesn't limit cache size to `prepareCacheLe…
Browse files Browse the repository at this point in the history
…ngth` #207
  • Loading branch information
rusher committed Oct 6, 2022
1 parent e004ecd commit dfb97ce
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 0 additions & 2 deletions lib/cmd/batch-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ class BatchBulk extends Parser {
this.bulkPacketNo--;

if (!this.sending && this.bulkPacketNo === 0) {
this.prepare.close();
this.packet = null;
if (this.firstError) {
this.resolve = null;
Expand Down Expand Up @@ -442,7 +441,6 @@ class BatchBulk extends Parser {

if (!this.sending && this.bulkPacketNo === 0) {
this.resolve = null;
this.prepare.close();
this.emit('send_end');
process.nextTick(this.reject, this.firstError);
this.reject = null;
Expand Down
4 changes: 1 addition & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ class Connection extends EventEmitter {
this.info
);

if (this.opts.prepareCacheLength > 0) {
this.info._prepareCache.onEviction = (key, value) => value.unCache();
}
this.on(
'close_prepare',
function (prepareResultPacket) {
Expand Down Expand Up @@ -243,6 +240,7 @@ class Connection extends EventEmitter {
return resolve(res);
},
function (err) {
prepare.close();
if (this.opts.logger.error) this.opts.logger.error(err);
reject(err);
}.bind(this),
Expand Down
7 changes: 5 additions & 2 deletions lib/misc/connection-information.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const QuickLRU = require('@alloc/quick-lru');
const LRU = require('lru-cache');

class ConnectionInformation {
constructor(opts) {
Expand All @@ -8,7 +8,10 @@ class ConnectionInformation {
this.serverVersion = null;
this.serverCapabilities = null;
if (opts.prepareCacheLength > 0) {
this._prepareCache = new QuickLRU({ maxSize: opts.prepareCacheLength });
this._prepareCache = new LRU({
max: opts.prepareCacheLength,
dispose: (value, key) => value.unCache()
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"author": "Diego Dupin <diego.dupin@mariadb.com>",
"license": "LGPL-2.1-or-later",
"dependencies": {
"@alloc/quick-lru": "^5.2.0",
"@types/geojson": "^7946.0.10",
"@types/node": "^17.0.45",
"denque": "^2.1.0",
"iconv-lite": "^0.6.3",
"lru-cache": "^7.14.0",
"moment-timezone": "^0.5.34"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('basic query', () => {
await conn.query('CREATE TABLE testArrayParameter (val1 int, val2 int)');
await conn.query('INSERT INTO testArrayParameter VALUES (1,1), (1,2), (1,3), (2,2)');

const query = "SELECT * FROM testArrayParameter WHERE val1 = ? AND val2 IN (?)";
const res = await conn.query(query, [1, [1,3]]);
const query = 'SELECT * FROM testArrayParameter WHERE val1 = ? AND val2 IN (?)';
const res = await conn.query(query, [1, [1, 3]]);
assert.deepEqual(res, [
{
val1: 1,
Expand Down

0 comments on commit dfb97ce

Please sign in to comment.