Optimization. Get a specific value (and no more) from IndexedDB

What I am doing is saving and retrieving a batch of images on the client.

(Now indexedDB seemed to be superfluous for this simple job, but since it was the only Cross-Browser solution without restriction (like localStorage), I had to use it ... and it works)

This is what my db looks like: (more specific, the only object store of my db)

# | key (timeID) | Value

0 | 812378123 | {data: ¨ .... ¨, tnData: ¨ ... ¨, timeID: 812378123}

1 | 912378123 | {data: ¨ .... ¨, tnData: ¨ ... ¨, timeID: 912378123}

2 ....

KeyValue is a unique TimeID, the data contains the image as text, and tnData contains the thumbnail of this image as text (when canvas.toBlob () is ready, I will switch to this)

To get the image, I just use store.get (id)

Now it all works.

But now I just want to download Thumbnail (¨tnData¨) - but NOT a real image (¨data¨, which can be quite large).

So, I hope there is something like store.get (id, ¨tnData¨) ...

But I have not found it yet. Does anyone know of a simple way to do this without redoing your db?

Thanks in advance ... and I'm sorry if I'm not in the right place or have violated some other rule ... the first question for me;)

+6
source share
1 answer

Does anyone know an easy way to do this without recycling my db?

No, IndexedDB does not allow only part of an object to be returned.

Recycling your db, though, may not be too complicated. You can break it into two stores of objects: one for thumbnails and one for whole images. Then you can request exactly the one you need.

If you often get both at the same time, you will need to benchmark and see if it really happens faster to break them, or maybe it makes sense to duplicate thumbnails (one repository of objects, for example, you have now and you only have thumbnails).

+3
source

All Articles