- opt[:conditions] = ['public = true']
- opt[:order] = 'timestamp DESC'
- opt[:limit] = 20
-
- if @page > 0
- opt[:offset => 20*@page]
+ opt[:include] = [:user, :tags] # load users and tags from db at same time as traces
+
+ # four main cases:
+ # 1 - all traces, logged in = all public traces + all user's (i.e + all mine)
+ # 2 - all traces, not logged in = all public traces
+ # 3 - user's traces, logged in as same user = all user's traces
+ # 4 - user's traces, not logged in as that user = all user's public traces
+ if target_user.nil? # all traces
+ if @user
+ conditions = ["(public = 1 OR user_id = ?)", @user.id] #1
+ else
+ conditions = ["public = 1"] #2
+ end
+ else
+ if @user and @user.id == target_user.id
+ conditions = ["user_id = ?", @user.id] #3 (check vs user id, so no join + can't pick up non-public traces by changing name)
+ else
+ conditions = ["public = 1 AND user_id = ?", target_user.id] #4
+ end