SQLite | How efficient is my code?

Discussion in 'Plugin Development' started by recon88, Dec 6, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    recon88

    Well I'm pretty new to SQL. I know the standards but I don't know how to write efficient stuff with it.
    What I got for testing purpose:
    - The plugin checks on every BlockBreak (stone) if the player exists
    - If not it creates the default set for this player
    - If yes it sets stone +1 on that player

    getValues() = Query which checks a ResultSet

    - Three queries for every new set (it's also created on PlayerLogin if it doesn't exist but I got a command to delete a player, so 3 queries in that case)?
    - Two queries for every stone.

    Isn't that kinda inefficient in SQLite?

    Code:java
    1.  
    2.  
    3.  
    4. @EventHandler
    5. public void onBlockBrake(BlockBreakEvent event) {
    6. Block blocktype = event.getBlock();
    7. String playername = event.getPlayer().getName().toLowerCase();
    8. if (blocktype.getType().equals(Material.STONE)) {
    9. if (plugin.getValues(playername) == null) {
    10. plugin.sqlite.query("INSERT INTO ore (playername, stone) VALUES('"+playername+"', '0');");
    11. }
    12. plugin.sqlite.query("UPDATE ore SET stone = stone + 1 WHERE playername = '" + playername + "'");
    13. }
    14. }
    15.  
     
  2. Offline

    md_5

    Thats really about as efficient and simple as you can get with SQlite. Shouldn't be an issue at all, if you find it to be an issue save to a list of pending queries and write them async every so often.
     
  3. Offline

    recon88

    I mean: Imaging there are 100 players mining. That would be more than 200 queries/sec (depends on pickaxe).
    I don't know much about about SQLite but is there a cache or something like that to avoid high HDD I/O?
    If not, wouldn't it be the same as using a plain file to store that stuff?
     
Thread Status:
Not open for further replies.

Share This Page