Skip to content

Commit f2abaa8

Browse files
committed
Cache lazy-evaluated field
Reading the data from the buffer repeatedly can be quite slow. Caching this data can make it to be significantly faster. Sequelize Before Change Call to doSomething took 2571.7481999993324 milliseconds Sequelize After Change Call to doSomething took 1230.2330999970436 milliseconds
1 parent 0dd8e16 commit f2abaa8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/packets/column_definition.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,19 @@ const addString = function(name) {
112112
get: function() {
113113
const start = this[`_${name}Start`];
114114
const end = start + this[`_${name}Length`];
115-
return StringParser.decode(
115+
const val = StringParser.decode(
116116
this._buf.slice(start, end),
117117
this.encoding === 'binary' ? this._clientEncoding : this.encoding
118118
);
119+
120+
Object.defineProperty(this, name, {
121+
value: val,
122+
writable: false,
123+
configurable: false,
124+
enumerable: false
125+
});
126+
127+
return val;
119128
}
120129
});
121130
};

0 commit comments

Comments
 (0)