Skip to content

Commit

Permalink
Improved handling of missing character data from API
Browse files Browse the repository at this point in the history
If character class data is missing, first check and see if we have the character info, and if we do, don't update.
  • Loading branch information
mikechambers committed Dec 17, 2022
1 parent caa037f commit ec31a6d
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 33 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# dcli Release Notes

## v0.95.0 December 17, 2022

- Improved handling of missing character class data from API

## v0.94.0 December 13, 2022

- Fix corrupted Rift matches (mode set to 0)
Expand Down
18 changes: 9 additions & 9 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dcli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dcli"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Library for the dcli collection of command line tools for Destiny 2."
Expand Down
45 changes: 31 additions & 14 deletions src/dcli/src/activitystoreinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,18 +1367,12 @@ impl ActivityStoreInterface {
//if some data is missing, we see if we already have info on
//this member stored.

let row_id: i32 = match self.get_member_row_id(member).await {
Ok(e) => e,
Err(_e) => -1,
match self.get_member_row_id(member).await {
Ok(e) => return Ok(e),
Err(_e) => {}
};

//if we do have something stored, just return that entry, otherwise,
//add it to the DB, even though the name info in missing
if row_id != -1 {
return Ok(row_id);
}

//if the DCLI_FIX_DATA environemnt variable is set to true
//if the DCLI_FIX_DATA environment variable is set to true
//the code will try and fix corrupt data with additional API
//calls. This can dramatically slow down the first time data is
//synced, but can help fix missing data
Expand Down Expand Up @@ -1428,9 +1422,9 @@ impl ActivityStoreInterface {
.execute(&mut self.db)
.await?;

let rowid: i32 = self.get_member_row_id(member).await?;
let row_id: i32 = self.get_member_row_id(member).await?;

Ok(rowid)
Ok(row_id)
}

async fn get_member_row_id(
Expand All @@ -1457,6 +1451,29 @@ impl ActivityStoreInterface {
class_type: &CharacterClass,
member_rowid: i32,
) -> Result<i32, Error> {
// Check if clas_type is Unknown (Missing data in API)
// If it is, then first see if we already have the character in the DB
// and if so, just return that row. That way, once we have valid data
// in the db, we never overwrite it with invalid data
if *class_type == CharacterClass::Unknown {
match sqlx::query(
r#"
SELECT id from "character" where character_id=? and member=?
"#,
)
.bind(character_id.to_string())
.bind(format!("{}", member_rowid))
.fetch_one(&mut self.db)
.await
{
Ok(e) => {
let id: i32 = e.try_get("id")?;
return Ok(id);
}
Err(_e) => {}
};
}

sqlx::query(
r#"
INSERT OR IGNORE into "character" ("character_id", "member", "class") VALUES (?, ?, ?)
Expand All @@ -1478,9 +1495,9 @@ impl ActivityStoreInterface {
.fetch_one(&mut self.db)
.await?;

let rowid: i32 = row.try_get("id")?;
let row_id: i32 = row.try_get("id")?;

Ok(rowid)
Ok(row_id)
}

async fn get_max_activity_id(
Expand Down
2 changes: 1 addition & 1 deletion src/dclia/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dclia"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
description = "Command line tool for retrieving information on current activity for specified player character."
homepage = "https://www.mikechambers.com"
Expand Down
2 changes: 1 addition & 1 deletion src/dcliad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dcliad"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for viewing Destiny 2 activity details."
Expand Down
2 changes: 1 addition & 1 deletion src/dcliah/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dcliah"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for viewing Destiny 2 activity history."
Expand Down
2 changes: 1 addition & 1 deletion src/dclif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dclif"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for querying specific Destiny 2 pvp stats."
Expand Down
2 changes: 1 addition & 1 deletion src/dclim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dclim"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for managing and syncing the remote Destiny 2 API manifest database."
Expand Down
2 changes: 1 addition & 1 deletion src/dclistat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dclistat"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for querying specific Destiny 2 pvp stats."
Expand Down
2 changes: 1 addition & 1 deletion src/dclisync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dclisync"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for downloading and syncing Destiny 2 Crucible activity history."
Expand Down
2 changes: 1 addition & 1 deletion src/dclitime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dclitime"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Command line tool for retrieving Destiny 2 related date / time stamps"
Expand Down
2 changes: 1 addition & 1 deletion src/tell/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tell"
#version
version = "0.94.0"
version = "0.95.0"
authors = ["Mike Chambers <[email protected]>"]
edition = "2018"
description = "Simple library for handling different levels of user output for command line apps."
Expand Down

0 comments on commit ec31a6d

Please sign in to comment.