Skip to content

Commit

Permalink
Allocate only required number of rows retrieved from SQL
Browse files Browse the repository at this point in the history
- Limit rows to MAX_STORAGE, as additional rows are unnecessary.
- Loops based on capped number of rows so we avoid iterating empty items
  • Loading branch information
jasonch35 committed Jan 29, 2025
1 parent 761ea97 commit f2c4ffe
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/char/int_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ static int inter_storage_fromsql(int account_id, int storage_id, struct storage_

StrBuf->Destroy(&buf);

if (SQL->NumRows(inter->sql_handle) > 0) {
VECTOR_ENSURE(p->item, MAX_STORAGE, 1);
int num_rows = SQL->NumRows(inter->sql_handle) > MAX_STORAGE ? MAX_STORAGE : (int)SQL->NumRows(inter->sql_handle);

for (int j = 0; j < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++j) {
if (num_rows > 0) {
VECTOR_ENSURE(p->item, num_rows, 1);

for (int j = 0; j < num_rows && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++j) {
struct item item = { 0 };
SQL->GetData(inter->sql_handle, 0, &data, NULL); item.id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); item.nameid = atoi(data);
Expand Down

0 comments on commit f2c4ffe

Please sign in to comment.