Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto delete MetaData when = 0 #8770

Merged
merged 2 commits into from
May 2, 2020
Merged

Conversation

Lejo1
Copy link
Contributor

@Lejo1 Lejo1 commented Aug 9, 2019

We still automatic delete a key of a metadata or mod_storage data if it is = ""
This PR also auto deletes if it is = 0
As we basically also return 0 for no value this makes no compatibility problems
This saves memory when mods for example remove a player and set the var to default = 0

How to test

local storage = minetest.get_mod_storage()

storage:set_string("placeholder", "make sure file is not null")

storage:set_int("int", 100)
storage:set_int("int", 0)
storage:set_float("float", 100.1)
storage:set_float("float", 0)

storage:set_float("float2", 100.1)
storage:set_float("float2", 0.0)

storage:set_string("string", "stringggggggggggg")
storage:set_string("string", "")

All the entries will disappear without the PR float, float2 and int will stay = 0

@SmallJoker
Copy link
Member

The only issue I can see is when you mix MetaRef:get() and MetaRef:set_int(). Latter will write "0", but former will return nil. In terms of storage optimization this is totally fine.

@Lejo1
Copy link
Contributor Author

Lejo1 commented Aug 9, 2019

In my case it’s a money mod. Where I only use set_int and get_int.
When creating a function to fully reset a player including all data of all
mods I came up to this.

@Moth-Tolias
Copy link

what's the status on this?

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nerzhul nerzhul merged commit 808eb4c into minetest:master May 2, 2020
@Lejo1 Lejo1 deleted the metadata_autoremove branch May 2, 2020 17:41
appgurueu added a commit to appgurueu/minetest that referenced this pull request Jul 13, 2020
SmallJoker pushed a commit that referenced this pull request Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants