Skip to content

Commit

Permalink
allow running with custom context in endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
shouya committed Sep 30, 2024
1 parent cc35528 commit 36b527c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/server/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,21 +310,17 @@ impl EndpointService {
})
}

pub async fn run(self, param: EndpointParam) -> Result<Feed> {
let mut context = FilterContext::from_param(&param);
pub async fn run_with_context(
self,
context: &mut FilterContext,
param: EndpointParam,
) -> Result<Feed> {
let feed = self
.source
.fetch_feed(&context, Some(&self.client))
.fetch_feed(context, Some(&self.client))
.await
.map_err(|e| Error::FetchSource(Box::new(e)))?;
if let Some(filter_skip) = param.filter_skip {
context.set_filter_skip(filter_skip);
}
if let Some(base) = param.base {
context.set_base(base);
}
// TODO: change filter pipeline to operate on a borrowed context
let mut feed = self.filters.run(context.clone(), feed).await?;
let mut feed = self.filters.run(context, feed).await?;

if let (Some(on_the_fly_filter), Some(query)) =
(self.on_the_fly_filter, param.query)
Expand All @@ -343,6 +339,12 @@ impl EndpointService {
Ok(feed)
}

pub async fn run(self, param: EndpointParam) -> Result<Feed> {
let mut context = FilterContext::from_param(&param);
let feed = self.run_with_context(&mut context, param).await?;
Ok(feed)
}

pub fn config_changed(&self, config: &EndpointServiceConfig) -> bool {
self.config != *config
}
Expand Down

0 comments on commit 36b527c

Please sign in to comment.