siuying / NanoStoreInMotion

RubyMotion wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite.
Other
103 stars 24 forks source link

Ui blocks on create methods #37

Closed benbonnet closed 10 years ago

benbonnet commented 10 years ago

I'm using the nanodb with ruby motion to store data locally. As you use the app, remote services are called once in a while, data saved in the db.

It does grow with time (as any db would do), but for a thousand entries the app got quite stuck on the ui side while creating models. Surprisingly, the finds queries are pretty stable.

I would be glad to get some feedback on what's happening, if you see something right here best

siuying commented 10 years ago

Like any long running tasks, writing to database should not run in the main thread. One way to do it is create a private background queue and only write databases on the queue. Note every update to UIKit must be done on main thread, so you need to be careful.

Some references:

benbonnet commented 10 years ago

perfect, thanks for this reply. to be clear, a "create" query can be considered as a long running task, while a "select" one is not ?

siuying commented 10 years ago

It really depends on your use case. If you have millions of records, a #find could be slow. A simple #find_by_key should be relatively fast in most case.