Skip to content

improve: optimization of new shop (store)#1159

Merged
mehah merged 1 commit intoopentibiabr:mainfrom
Nottinghster:main
May 19, 2025
Merged

improve: optimization of new shop (store)#1159
mehah merged 1 commit intoopentibiabr:mainfrom
Nottinghster:main

Conversation

@Nottinghster
Copy link
Copy Markdown
Contributor

The main improvements implemented in the code are:

Cache System for Points:

* Added a cache system to reduce frequent database queries.
* The cache expires after 5 minutes to ensure that the data is updated periodically.

Optimization of Infinite Loop:

* Added a counter to limit the number of executions of the refreshPlayersPoints function.
* The counter is stored in GlobalStorage for persistence.

Single Initialization of the Shop:

* Implemented a check to prevent the shop from being initialized multiple times.
* This reduces memory usage and redundant processing.

String Construction Optimization:

* Replaced excessive concatenations with table construction and table.concat().
* This approach is much more efficient in Lua.

Event Consolidation:

* Created a unified updatePlayerShopData function to reduce the number of event calls.
* This reduces the overhead of scheduling events.

Cache Cleanup on Logout:

* Added a logout event to clear the cache when the player disconnects.
* This prevents memory accumulation from data of players who are no longer online.

Purchase History Limitation:

* Limited the purchase history to 50 records to avoid data overload.

Name Validation Optimization:

* Improved the efficiency of the validName function by using lookup tables and more direct checks.

The main improvements implemented in the code are:

>> Cache System for Points:
* Added a cache system to reduce frequent database queries.
* The cache expires after 5 minutes to ensure that the data is updated periodically.

>> Optimization of Infinite Loop:
* Added a counter to limit the number of executions of the refreshPlayersPoints function.
* The counter is stored in GlobalStorage for persistence.

>> Single Initialization of the Shop:
* Implemented a check to prevent the shop from being initialized multiple times.
* This reduces memory usage and redundant processing.

>> String Construction Optimization:
* Replaced excessive concatenations with table construction and table.concat().
* This approach is much more efficient in Lua.

>> Event Consolidation:
* Created a unified updatePlayerShopData function to reduce the number of event calls.
* This reduces the overhead of scheduling events.

>> Cache Cleanup on Logout:
* Added a logout event to clear the cache when the player disconnects.
* This prevents memory accumulation from data of players who are no longer online.

>> Purchase History Limitation:
* Limited the purchase history to 50 records to avoid data overload.

>> Name Validation Optimization:
* Improved the efficiency of the validName function by using lookup tables and more direct checks.
@ericcobblepot
Copy link
Copy Markdown

ericcobblepot commented May 16, 2025

This is the fourth (from game_shop) commit in less than five days. Could you leave the PR open for at least a week? That way, you can introduce future changes or whatever you have planned within seven days, and then it can be merged into the branch.

Just to keep the main repo commits cleaner.

I hope my comment doesn't bother you.

@sonarqubecloud
Copy link
Copy Markdown

@mehah mehah merged commit ae47b27 into opentibiabr:main May 19, 2025
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants