Save data in Ruby on Rails without a database

I have several data values ​​that I need to store in my rails application, and wanted to find out if there are any alternatives to creating a database table just for this simple task.

Background: I am writing some analytics tools and toolbars for my ruby ​​ruils application, and I hope to speed up the dashboard by caching results that will never change. Right now I am pulling all users over the last 30 days and rebuilding them so that I can see the number of new users per day. It works fine, but takes quite a lot of time, in fact I just need to calculate the very last day and just save the rest of the array in another place.

Where is the best place to store this array?

Creating a database table seems a bit redundant, and I'm not sure if global variables are the right answer. Is there a best practice for such data?

If someone did something like this before letting me know what you did and how it happened.

+5
source share
3 answers

Ruby has a built-in Hash-based key storage called PStore. This provides simple file-based transactional resilience.

+11
source

, sqlite, . , , tokyo-, , sqlite.

+1

, . , , , . , SQL, , - .

At the same time, the type of report that you are trying to create is actually what you can do in real time, with the exception of extravagantly large data sets. The key should have indexes that describe the exact grouping operation you are trying to do. For example, if you group by calendar date, you can create a "date" field and synchronize it with "created_at" time as needed. The index of this field gives very fast execution of GROUP BY created_date:

SELECT created_date AS on_date, COUNT(id) AS new_users FROM users GROUP BY created_date
+1
source

All Articles