mysql - Is it better to store list of each user's Blocked users for query exclusion in $_SESSION var, or to exclude in "real-time" with sub-query? -


on 1 of php/mysql sites, every user can block every other user on site. these blocks stored in blocked table each row representing did blocking , target of block. columns indexed faster retrieval of user's entire "block list".

for each user, must exclude search results user appears in block list.

in order that, better to:

1) generate "block list" whenever user logs in querying blocked table once @ login , saving $_session (and re-querying time make change "block list" , re-saving $_session), , querying such:

not in ($commaseparatedlistfromsession)

or

2) exclude blocked users in "real-time" directly in query using sub-query each user's search query such:

not in (select userid blocked blocked.from = $currentuserid) ?

don't use $_session substitute proper caching system. more junk pile $_session, more you'll have load each , every request.

using sub-select exclusions can brutally slow if you're not careful keep database tuned. make sure indexes covering where conditions.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

Delphi interface implements -

trac - Modifying workflow to add a status and split on ticket type -