Skip to content

Commit

Permalink
Merge pull request #991 from golemfactory/version/fake_skip
Browse files Browse the repository at this point in the history
Still show seen versions in GSB and CLI
  • Loading branch information
tworec authored Jan 29, 2021
2 parents ed42183 + ed65a40 commit 90d5eea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 8 additions & 6 deletions core/version/src/db/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ impl<'c> ReleaseDAO<'c> {
}

pub async fn pending_release(&self) -> anyhow::Result<Option<Release>> {
readonly_transaction(self.pool, move |conn| get_pending_release(conn)).await
readonly_transaction(self.pool, move |conn| get_pending_release(conn, false)).await
}

pub async fn version(&self) -> anyhow::Result<VersionInfo> {
log::debug!("Getting Yagna version: current and pending from DB");
readonly_transaction(self.pool, move |conn| {
Ok(VersionInfo {
current: get_current_release(conn)?.ok_or(anyhow!("Can't get current release."))?,
pending: get_pending_release(conn)?,
pending: get_pending_release(conn, true)?,
})
})
.await
Expand All @@ -58,7 +58,7 @@ impl<'c> ReleaseDAO<'c> {
pub async fn skip_pending_release(&self) -> anyhow::Result<Option<Release>> {
log::debug!("Skipping latest pending Yagna release");
do_with_transaction(self.pool, move |conn| {
let mut pending_rel = match get_pending_release(conn)? {
let mut pending_rel = match get_pending_release(conn, false)? {
Some(rel) => rel,
None => return Ok(None),
};
Expand Down Expand Up @@ -88,12 +88,14 @@ fn get_release(conn: &ConnType, ver: &str) -> anyhow::Result<Option<Release>> {
.map(|db_rel| db_rel.into()))
}

fn get_pending_release(conn: &ConnType) -> anyhow::Result<Option<Release>> {
let query = version_release
.filter(release::seen.eq(false))
fn get_pending_release(conn: &ConnType, include_seen: bool) -> anyhow::Result<Option<Release>> {
let mut query = version_release
// insertion_ts is to distinguish among fake-entries of `DBRelease::current`
.order((release::release_ts.desc(), release::insertion_ts.desc()))
.into_boxed();
if !include_seen {
query = query.filter(release::seen.eq(false));
}

match query.first::<DBRelease>(conn).optional()? {
Some(db_rel) => {
Expand Down
6 changes: 2 additions & 4 deletions core/version/src/service/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const UPDATE_CMD: &'static str = "curl -sSf https://join.golem.network/as-provid

#[derive(thiserror::Error, Debug, Clone)]
pub(crate) enum ReleaseMessage<'a> {
#[error("New Yagna {0} is available!\nUpdate via\n\t`{UPDATE_CMD}`")]
#[error("New Yagna {0} is available! Update via `{UPDATE_CMD}`")]
Available(&'a version::Release),
#[error("Your Yagna is up to date: {0}")]
UpToDate(&'a version::Release),
Expand Down Expand Up @@ -81,9 +81,7 @@ mod test {
assert_eq!(
ReleaseMessage::Available(&r).to_string(),
format!(
"New Yagna Version 0.6.1 'some code name' released 2015-10-13 is available!\n\
Update via\n\
\t`curl -sSf https://join.golem.network/as-provider | bash -`"
"New Yagna Version 0.6.1 'some code name' released 2015-10-13 is available! Update via `curl -sSf https://join.golem.network/as-provider | bash -`"
)
);
}
Expand Down

0 comments on commit 90d5eea

Please sign in to comment.