开发者

Should I save site vital data to database [closed]

开发者 https://www.devze.com 2023-04-02 05:08 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_如何学C
Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_如何学C

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

Improve this question

On my site when some user create profile he also choose his school name. Schools have the table in database. The main page in applicatioin should display some data about users school. And there are a few links that display something based on school ID.

Now I have two options:

  1. When user log in I get SchoolID based on userID and save it in session?
  2. Whenever I need to open something that request schoolID I send call to database to get schoolID based on userID?
  3. Something else.

Performance and security are my proprities becaouse thera are a lot users.


The performance gain by caching the schoolId is so minor that number 2 is your best option. Getting the schoolId based on userId would be a very quick lookup. Number 1 has the potential bug that you forget to update session when the user edits their school. It also assumes that schoolId would only be set within the session. The day you break that assumption by importing updates or the admin updates, the session will not match the data and all sorts of problems may ensue.

Of course, getting the school data should be one command: select School.* from School inner join User on User.SchoolId = School.SchoolId where User.UserId = @UserId

0

精彩评论

暂无评论...
验证码 换一张
取 消