Lymkwi / python-minetest

A python library to manipulate minetest's files
6 stars 3 forks source link

functions for db management #4

Closed ghost closed 8 years ago

ghost commented 8 years ago

I was thinking it might be handy to have functions to copy entire contents of one database to another, as well as to empty a map and delete individual mapblocks. also maybe copying one mapblock to another? I only suggest the latter in the hopes that it avoids the costly explode/implode for blocks that are identical, which may or may not be a rare occurrence...

Lymkwi commented 8 years ago

I was thinking it might be handy to have functions

It always is, for many purposes.

to copy entire contents of one database to another

For now the only table used by the library is the block table, so I'll talk about nodes and mapblocks for now. There could indeed be a function to copy mapblocks from one world to another directly. You could currently do that by manipulating the two db vessels' caches but that would be tricky and hacky.

empty a map

I thought of that for a while, and it's actually very easy to implement with MapVessel.get_all_mapblock_ids and MapVessel.remove. I will add it, tomorrow probably.

.delete individual mapblocks

The documentation isn't ready yet so you probably missed it : MapVessel.remove : https://github.com/LeMagnesium/python-minetest/blob/master/libminetest/map.py#L535

also maybe copying one mapblock to another?

You could clone mapblocks, yes, but considering the staged imports (first binary from SQLite, then mapblock from the cache, manipulated, saved in binary in the vessel, sent in SQL command to the DB's cache, written at commit), that would be useless for mapblocks that are identical. First, you can't say whether or not they are identical before the explosion of the binary data, and second, you would have to remember the mapblocks you already loaded, or inspect them to check for similarities, which would take forever. Plus, copying each node object would take more time to run than what I plan on doing when initializing the mapblock : empty entries in a Mapblock's node dictionaries for nodes that are air with no metadata, no timer, etc..