Properly filter user's subscriptions in search
This commit is contained in:
		| @@ -430,6 +430,13 @@ get "/search" do |env| | |||||||
|   page = env.params.query["page"]?.try &.to_i? |   page = env.params.query["page"]?.try &.to_i? | ||||||
|   page ||= 1 |   page ||= 1 | ||||||
|  |  | ||||||
|  |   user = env.get? "user" | ||||||
|  |   if user | ||||||
|  |     user = user.as(User) | ||||||
|  |     ucids = user.subscriptions | ||||||
|  |   end | ||||||
|  |   ucids ||= [] of String | ||||||
|  |  | ||||||
|   channel = nil |   channel = nil | ||||||
|   date = "" |   date = "" | ||||||
|   duration = "" |   duration = "" | ||||||
| @@ -467,8 +474,8 @@ get "/search" do |env| | |||||||
|         to_tsvector(channel_videos.title) || |         to_tsvector(channel_videos.title) || | ||||||
|         to_tsvector(channel_videos.author) |         to_tsvector(channel_videos.author) | ||||||
|           as document |           as document | ||||||
|       FROM channel_videos |       FROM channel_videos WHERE ucid IN (#{arg_array(ucids, 3)}) | ||||||
|     ) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;", search_query, (page - 1) * 20, as: ChannelVideo) |     ) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;", [search_query, (page - 1) * 20] + ucids, as: ChannelVideo) | ||||||
|     count = videos.size |     count = videos.size | ||||||
|   else |   else | ||||||
|     search_params = build_search_params(sort: sort, date: date, content_type: "video", |     search_params = build_search_params(sort: sort, date: date, content_type: "video", | ||||||
|   | |||||||
| @@ -95,6 +95,8 @@ def fetch_channel(ucid, client, db, pull_all_videos = true) | |||||||
|         videos = extract_videos(nodeset) |         videos = extract_videos(nodeset) | ||||||
|       else |       else | ||||||
|         videos = extract_videos(nodeset, ucid) |         videos = extract_videos(nodeset, ucid) | ||||||
|  |         videos.each { |video| video.ucid = ucid } | ||||||
|  |         videos.each { |video| video.author = author } | ||||||
|       end |       end | ||||||
|  |  | ||||||
|       count = nodeset.size |       count = nodeset.size | ||||||
| @@ -103,11 +105,12 @@ def fetch_channel(ucid, client, db, pull_all_videos = true) | |||||||
|       videos.each do |video| |       videos.each do |video| | ||||||
|         ids << video.id |         ids << video.id | ||||||
|         db.exec("UPDATE users SET notifications = notifications || $1 \ |         db.exec("UPDATE users SET notifications = notifications || $1 \ | ||||||
|           WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, ucid) |           WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, video.ucid) | ||||||
|  |  | ||||||
|         video_array = video.to_a |         video_array = video.to_a | ||||||
|         args = arg_array(video_array) |         args = arg_array(video_array) | ||||||
|         db.exec("INSERT INTO channel_videos VALUES (#{args}) ON CONFLICT (id) DO UPDATE SET published = $3", video_array) |         db.exec("INSERT INTO channel_videos VALUES (#{args}) ON CONFLICT (id) DO UPDATE SET title = $2, \ | ||||||
|  |           published = $3, updated = $4, ucid = $5, author = $6", video_array) | ||||||
|       end |       end | ||||||
|  |  | ||||||
|       if count < 30 |       if count < 30 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Omar Roth
					Omar Roth