Matrix storage in Rails?

I'm wondering what is the best way to handle the huge matrix in Rails 3. This matrix will keep the distance between the points (this is symmetrical).

Points can be added at any time, so the matrix can be updated frequently.

I see two ways:

  • storing values ​​in a database and getting distances through db queries (easy but a little slower)
  • save the values ​​in a file and put this file in the cache (it can be difficult to update)

Thoughts?

PS: I am packing this for a new version of my gmaps4rails gem (designed to easily create gmaps for rails users)

+4
source share
1 answer

If you need to keep a unique and large matrix, I would recommend doing this in a separate table (column / row / value). It will scale better than with a file, and:

  • You can easily and easily update individual cells.
  • You mentioned using a file to cache your matrix, but if you need to, you can also get your entire table to cache your matrix.
  • You can update rows, columns and sub-matrices with well-formed queries.

If you encounter performance issues when increasing the size of the matrix, check out the activerecord-import library. This will help you insert data into your matrix.

+1
source

Source: https://habr.com/ru/post/1333486/


All Articles