Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Question

Posted

Many of us use different methods for storing data, and there may be users who are not entirely sure what options exist and when to use each one.

Perhaps there is a Fibaro developer or a more advanced user with a deeper understanding of this topic who could share their knowledge with those of us who are less familiar with it (including me).

As far as I understand, there are three ways to persistently store data in a QuickApp:

1. QuickApp Variables

These can be read directly using self:getVariable() and their scope is limited to the QuickApp itself.

2. Global Variables

These are read using hub.getGlobalVariable() and their scope is the entire system.

3. Internal Storage

(This is something I only recently learned about.)
I am not entirely sure about the typical usage of this method, but I assume the scope is also system-wide.


Questions

If you need to store a larger amount of data, for example a JSON table with around 500 elements:

  • Which storage method would be preferable?

  • Which option consumes the least memory?

  • Which option provides the fastest read/write performance?

  • Which option is considered the safest or most reliable?

Any insights or recommendations would be greatly appreciated.

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

Not a big difference in speed.
They consume more or less the same amount of memory as the value is json encoded in all cases.
Safest or most reliable? depends...

I believe that the choice is up to what visibility is wanted...
 

Please login or register to see this spoiler.

 

Test with table having 500 keys/values.

Please login or register to see this code.


The Quickapp:getVariable is so fast as the value is cached in the QA and no API or json.decode is needed.
On the other hand setVariable/GetVariable saves and restore all quickVars when needed and searches linearly through the list of variables, so its speed decreases with number of variables...

Edited by jgab
  • Like 1
  • 0
  • Inquirer
  • Posted

    Meanwhile, I received some information from JGAB about internal storage usage.

    The available methods are:

    Please login or register to see this code.

     
    QuickApp:internalStorageGet(key)
    QuickApp:internalStorageSet(key, value)
    QuickApp:internalStorageRemove(key)
     

    He also mentioned that there are some tricks for retrieving all keys and even hiding them.

    One very elegant approach is to create a metatable in self.store and use that as a wrapper for persistent values, like this:

    Please login or register to see this code.

     

    Please login or register to see this code.

     

     

    With this approach, self.store.x behaves almost like a normal Lua table field, while the data is actually stored in the QuickApp’s internal storage.

    2 minutes ago, jgab said:

    Not a big difference in speed.
    They consume more or less the same amount of memory as the value is json encoded in all cases.
    Safest or most reliable? depends...

    I believe that the choice is up to what visibility is wanted...
     

    Please login or register to see this spoiler.

    Do you have any info about the data size limit that can be stored in each of them?

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...