Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out past live events from search results in backend #1062

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/src/api/model/search/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::Utc;
use once_cell::sync::Lazy;
use regex::Regex;
use std::{fmt, borrow::Cow};
Expand Down Expand Up @@ -141,6 +142,11 @@ pub(crate) async fn perform(
let filter = Filter::And(
std::iter::once(Filter::Leaf("listed = true".into()))
.chain(acl_filter("read_roles", context))
// Filter out live events that are already over.
.chain([Filter::Or([
Filter::Leaf("is_live = false ".into()),
Filter::Leaf(format!("end_time_timestamp >= {}", Utc::now().timestamp()).into()),
].into())])
.collect()
).to_string();
let mut event_query = context.search.event_index.search();
Expand Down
7 changes: 5 additions & 2 deletions backend/src/search/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) struct Event {
pub(crate) created: DateTime<Utc>,
pub(crate) start_time: Option<DateTime<Utc>>,
pub(crate) end_time: Option<DateTime<Utc>>,
pub(crate) end_time_timestamp: Option<i64>,
pub(crate) is_live: bool,
pub(crate) audio_only: bool,

Expand Down Expand Up @@ -65,6 +66,7 @@ impl_from_db!(
},
|row| {
let host_realms = row.host_realms::<Vec<Realm>>();
let end_time = row.end_time();
Self {
id: row.id(),
series_id: row.series(),
Expand All @@ -78,7 +80,8 @@ impl_from_db!(
audio_only: row.audio_only(),
created: row.created(),
start_time: row.start_time(),
end_time: row.end_time(),
end_time,
end_time_timestamp: end_time.map(|date_time| date_time.timestamp()),
read_roles: util::encode_acl(&row.read_roles::<Vec<String>>()),
write_roles: util::encode_acl(&row.write_roles::<Vec<String>>()),
listed: host_realms.iter().any(|realm| !realm.is_user_realm()),
Expand Down Expand Up @@ -113,6 +116,6 @@ pub(super) async fn prepare_index(index: &Index) -> Result<()> {
index,
"event",
&["title", "creators", "description", "series_title"],
&["listed", "read_roles", "write_roles"],
&["listed", "read_roles", "write_roles", "is_live", "end_time_timestamp"],
).await
}
2 changes: 1 addition & 1 deletion backend/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) use self::{

/// The version of search index schema. Increase whenever there is a change that
/// requires an index rebuild.
const VERSION: u32 = 3;
const VERSION: u32 = 4;


// ===== Configuration ============================================================================
Expand Down
13 changes: 3 additions & 10 deletions frontend/src/routes/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SearchQuery, SearchQuery$data } from "./__generated__/SearchQuery.graph
import { RouterControl, makeRoute } from "../rauta";
import { loadQuery } from "../relay";
import { Link, useRouter } from "../router";
import { Creators, isPastLiveEvent, Thumbnail } from "../ui/Video";
import { Creators, Thumbnail } from "../ui/Video";
import { SmallDescription } from "../ui/metadata";
import { Card } from "../ui/Card";
import { Breadcrumbs, BreadcrumbsContainer, BreadcrumbSeparator } from "../ui/Breadcrumbs";
Expand Down Expand Up @@ -141,13 +141,6 @@ const SearchResults: React.FC<SearchResultsProps> = ({ items }) => (
<ul css={{ listStyle: "none", padding: 0 }}>
{items.map(item => {
if (item.__typename === "SearchEvent") {
// Filter out live events that are over
const endTime = unwrapUndefined(item.endTime);
const isLive = unwrapUndefined(item.isLive);
if (isPastLiveEvent(endTime, isLive)) {
return null;
}

return <SearchEvent key={item.id} {...{
id: item.id,
title: unwrapUndefined(item.title),
Expand All @@ -157,11 +150,11 @@ const SearchResults: React.FC<SearchResultsProps> = ({ items }) => (
creators: unwrapUndefined(item.creators),
seriesTitle: unwrapUndefined(item.seriesTitle),
seriesId: unwrapUndefined(item.seriesId),
isLive,
isLive: unwrapUndefined(item.isLive),
audioOnly: unwrapUndefined(item.audioOnly),
created: unwrapUndefined(item.created),
startTime: unwrapUndefined(item.startTime),
endTime,
endTime: unwrapUndefined(item.endTime),
hostRealms: unwrapUndefined(item.hostRealms),
}}/>;
} else if (item.__typename === "SearchRealm") {
Expand Down