Write temporary data in the array or query the database

2

It is necessary to verify that the user has permission to view / edit data of a certain client.

This check occurs in almost all application operations.

Currently when I log in to the application, I make a single query on the database and check which clients are associated with the user and record it in a session.

When it is necessary to verify that the user has permission to view / edit client data, I make a FOR in the session and check if the client ID exists.

It turns out that there are users with permission to view / edit 5 clients and others with 300.

Burning in session and making a FOR will always be faster than a database query?

OBS : Data integrity is not a concern, only if reading an array will be faster than reading the database.

    
asked by anonymous 02.12.2014 / 20:08

2 answers

2

What happens if a new client is removed or authorized for this logged in user during the session? Home In the way that you are doing if the user never leaves the system he will never lose access or acquire new access.

Make inquiries whenever necessary, so you ensure that the user will always be doing what he can and will not be doing what he can not.

As much as you miss a few microseconds running the query, this failure can compromise the system's overall integrity.

    
02.12.2014 / 20:17
2

You should measure what is most important in your system and what are the consequences of each decision.

  • Querying the database ensures that your system will not suffer from possible inconsistencies that may occur if any of these access rules changes during the session.
  • Searching the database is easier and safer, indeed. However it is expensive and many queries can compromise the performance of your system.

  • In-Memory Query: If this permissions structure is something that will hardly change I do not see any problems with working with records in memory. In-memory queries are infinitely faster than disk queries (in this case, database).
  • In most cases looking for an element in the list will be faster than searching for an element in the database, but it is not 100% correct because there are techniques and situations that can improve or worsen performance, such as creating indexes in the bank, use of search-optimized lists can optimize the search. The list is too large and the element may be at the end of it, and a poorly designed database can slow the search down.

    I would particularly work with in-memory data if you were with a scenario like yours ..

    There are many factors and you should take all of this into account.     

    02.12.2014 / 20:34