| 975 | } |
| 976 | |
| 977 | _validateOverflow() { |
| 978 | if (this.length < this._maxPrepared) { |
| 979 | return; |
| 980 | } |
| 981 | |
| 982 | const toRemove = []; |
| 983 | this._logger('warning', |
| 984 | 'Prepared statements exceeded maximum. This could be caused by preparing queries that contain parameters'); |
| 985 | |
| 986 | const toRemoveLength = this.length - this._maxPrepared + 1; |
| 987 | |
| 988 | for (const [key, info] of this._mapByKey) { |
| 989 | if (!info.queryId) { |
| 990 | // Only remove queries that contain queryId |
| 991 | continue; |
| 992 | } |
| 993 | |
| 994 | const length = toRemove.push([key, info]); |
| 995 | if (length >= toRemoveLength) { |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | for (const [key, info] of toRemove) { |
| 1001 | this._mapByKey.delete(key); |
| 1002 | this._mapById.delete(info.queryId.toString('hex')); |
| 1003 | this.length--; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | setById(info) { |
| 1008 | this._mapById.set(info.queryId.toString('hex'), info); |