-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils/validateResultSet): add warning for oversized result sets
This behaviour is generally undesirable and may lead to excessive memory use or crashes.
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { OkPacket, ProcedureCallPacket, ResultSetHeader, RowDataPacket } from 'mysql2/promise'; | ||
|
||
const oversizedResultSet = GetConvarInt('mysql_resultset_warning', 1000); | ||
|
||
export default function ( | ||
invokingResource: string, | ||
query: string, | ||
rows: | ||
| OkPacket | ||
| ResultSetHeader | ||
| ResultSetHeader[] | ||
| RowDataPacket[] | ||
| RowDataPacket[][] | ||
| OkPacket[] | ||
| ProcedureCallPacket | ||
) { | ||
const length = Array.isArray(rows) ? rows.length : 0; | ||
|
||
if (length < oversizedResultSet) return; | ||
|
||
console.warn(`${invokingResource} executed a query with an oversized result set (${length} results)!\n${query}`); | ||
} |