Source: Refactor the clear_etags method api

This commit is contained in:
Jordan Petridis 2018-10-04 16:45:15 +03:00
parent e0b3dd9795
commit 7e3fecc44a
No known key found for this signature in database
GPG Key ID: E8523968931763BE

View File

@ -109,17 +109,12 @@ impl Source {
} }
/// Clear the `HTTP` `Etag` and `Last-modified` headers. /// Clear the `HTTP` `Etag` and `Last-modified` headers.
fn clear_etags(mut self) -> Result<Self, DataError> { /// This method does not sync the state of self in the database, call
if self.http_etag().is_some() || self.last_modified().is_some() { /// .save() method explicitly
debug!("Source etags before clear: {:#?}", &self); fn clear_etags(&mut self) {
self.http_etag = None; debug!("Source etags before clear: {:#?}", &self);
self.last_modified = None; self.http_etag = None;
self = self.save()?; self.last_modified = None;
debug!("Source etags after clear: {:#?}", &self);
info!("Etag fields cleared succesfully for Source: {}", self.uri);
}
Ok(self)
} }
fn make_err(self, context: &str, code: StatusCode) -> DataError { fn make_err(self, context: &str, code: StatusCode) -> DataError {
@ -147,7 +142,10 @@ impl Source {
// Save etags if it returns NotModified // Save etags if it returns NotModified
304 => self = self.update_etag(&res)?, 304 => self = self.update_etag(&res)?,
// Clear the Etag/lmod else // Clear the Etag/lmod else
_ => self = self.clear_etags()?, _ => {
self.clear_etags();
self = self.save()?;
}
}; };
}; };
@ -187,7 +185,8 @@ impl Source {
debug!("Previous Source: {:#?}", &self); debug!("Previous Source: {:#?}", &self);
self.set_uri(url.to_str()?.into()); self.set_uri(url.to_str()?.into());
self = self.clear_etags()?; self.clear_etags();
self = self.save()?;
debug!("Updated Source: {:#?}", &self); debug!("Updated Source: {:#?}", &self);
info!("Feed url of Source {}, was updated succesfully.", self.id()); info!("Feed url of Source {}, was updated succesfully.", self.id());