That's also how relational db works, it overwrite entire datafile (usually of 8kb) for every update/insert/delete, even that is just a single field in a single row
Granted, localstorage is larger than 8kb (usually something like 5MB if I remember correctly), but few MBs won't cause you any troubles in this day and age
Sqlite or any proper database won't work on the web, maybe that's the reason the original author opted for localstorage in the first place
Edit: idk if the code is for Android, if it is then it makes sense to me
Sadly I am the original author. This is a reimplementation of local storage in Kotlin, so it's not even the original thing - it runs locally, for a Discord bot.
It may work, but certainly doesn't feel right. IMHO, I should've been SQLite at worst, even though that would cause concurrency issues as well.
You are the one implementing the bot and how it stores data, then why would it run into concurrency issues? You don’t need the database to handle multithreading, you just need to handle it queue in the tasks and only use one thread for I/o anyway, that’s how you get performance and don’t thrash hard drives or impact performance. Everything in a pc is buffered and queued for a reason
Fuck me, I wasnt sure because of how the array declaration looks like Java. But ${} is string interpolation for JS so I went with JS, shoulda looked for the backticks. Was the kotlin flair always there? Or was I just blind
14
u/ForeverSJC Sep 11 '21
If you say this is bad code, your standards are really high
1
u/OkReview6132 Sep 11 '21 edited Sep 11 '21
I actually never thought of overloaded constructors being in nodejs, you just learnt me something!
Edit: oh this is TS
3
u/Nasatyau Sep 11 '21
This isn't great code, but I don't think its issues have anything to do with the storage medium 🤔
1
u/riseofthenothing Sep 11 '21
But have you tried the IndexedDB library?