Skip to content

Commit

Permalink
Uses _ instead of dead_code where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarik Eshaq committed Dec 19, 2021
1 parent 3033e50 commit 184c70f
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 83 deletions.
6 changes: 3 additions & 3 deletions components/fxa-client/src/internal/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ pub enum PushPayload {
Unknown,
}

// Some of this structs fields are not read, except
// when deserialized, we mark them as dead_code
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
pub struct CommandReceivedPushPayload {
#[allow(dead_code)]
command: String,
index: u64,
#[allow(dead_code)]
sender: String,
#[allow(dead_code)]
url: String,
}

Expand Down
12 changes: 6 additions & 6 deletions components/places/src/bookmark_sync/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2909,11 +2909,11 @@ mod tests {
let info_for_a = get_raw_bookmark(&writer, &guid_for_a)
.expect("Should fetch info for A")
.unwrap();
assert_eq!(info_for_a.sync_change_counter, 2);
assert_eq!(info_for_a._sync_change_counter, 2);
let info_for_unfiled = get_raw_bookmark(&writer, &BookmarkRootGuid::Unfiled.as_guid())
.expect("Should fetch info for unfiled")
.unwrap();
assert_eq!(info_for_unfiled.sync_change_counter, 2);
assert_eq!(info_for_unfiled._sync_change_counter, 2);

engine
.sync_finished(
Expand All @@ -2929,11 +2929,11 @@ mod tests {
let info_for_a = get_raw_bookmark(&writer, &guid_for_a)
.expect("Should fetch info for A")
.unwrap();
assert_eq!(info_for_a.sync_change_counter, 0);
assert_eq!(info_for_a._sync_change_counter, 0);
let info_for_unfiled = get_raw_bookmark(&writer, &BookmarkRootGuid::Unfiled.as_guid())
.expect("Should fetch info for unfiled")
.unwrap();
assert_eq!(info_for_unfiled.sync_change_counter, 0);
assert_eq!(info_for_unfiled._sync_change_counter, 0);

let mut tags_for_c = tags::get_tags_for_url(
&writer,
Expand Down Expand Up @@ -4322,8 +4322,8 @@ mod tests {
let bm = get_raw_bookmark(&writer, &guid.into())
.expect("must work")
.expect("must exist");
assert_eq!(bm.sync_status, SyncStatus::Normal, "{}", guid);
assert_eq!(bm.sync_change_counter, 0, "{}", guid);
assert_eq!(bm._sync_status, SyncStatus::Normal, "{}", guid);
assert_eq!(bm._sync_change_counter, 0, "{}", guid);
}
// And bookmarkEEEE wasn't on the server, so should be outgoing, and
// it's parent too.
Expand Down
45 changes: 20 additions & 25 deletions components/places/src/storage/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,11 @@ pub fn insert_tree(db: &PlacesDb, tree: &FolderNode) -> Result<()> {
#[derive(Debug)]
struct FetchedTreeRow {
level: u32,
#[allow(dead_code)]
id: RowId,
_id: RowId,
guid: SyncGuid,
// parent and parent_guid are Option<> only to handle the root - we would
// assert but they aren't currently used.
#[allow(dead_code)]
parent: Option<RowId>,
_parent: Option<RowId>,
parent_guid: Option<SyncGuid>,
node_type: BookmarkType,
position: u32,
Expand All @@ -1140,9 +1138,9 @@ impl FetchedTreeRow {
let url = row.get::<_, Option<String>>("url")?;
Ok(Self {
level: row.get("level")?,
id: row.get::<_, RowId>("id")?,
_id: row.get::<_, RowId>("id")?,
guid: row.get::<_, String>("guid")?.into(),
parent: row.get::<_, Option<RowId>>("parent")?,
_parent: row.get::<_, Option<RowId>>("parent")?,
parent_guid: row
.get::<_, Option<String>>("parentGuid")?
.map(SyncGuid::from),
Expand Down Expand Up @@ -1372,13 +1370,10 @@ pub(crate) struct RawBookmark {
pub date_added: Timestamp,
pub date_modified: Timestamp,
pub guid: SyncGuid,
#[allow(dead_code)]
pub sync_status: SyncStatus,
#[allow(dead_code)]
pub sync_change_counter: u32,
pub _sync_status: SyncStatus,
pub _sync_change_counter: u32,
pub child_count: u32,
#[allow(dead_code)]
pub grandparent_id: Option<RowId>,
pub _grandparent_id: Option<RowId>,
}

impl RawBookmark {
Expand All @@ -1401,12 +1396,12 @@ impl RawBookmark {
date_added: row.get("dateAdded")?,
date_modified: row.get("lastModified")?,
guid: row.get::<_, String>("guid")?.into(),
sync_status: SyncStatus::from_u8(row.get::<_, u8>("_syncStatus")?),
sync_change_counter: row
_sync_status: SyncStatus::from_u8(row.get::<_, u8>("_syncStatus")?),
_sync_change_counter: row
.get::<_, Option<u32>>("syncChangeCounter")?
.unwrap_or_default(),
child_count: row.get("_childCount")?,
grandparent_id: row.get("_grandparentId")?,
_grandparent_id: row.get("_grandparentId")?,
})
}
}
Expand Down Expand Up @@ -1679,14 +1674,14 @@ mod tests {
assert_eq!(rb.position, 0);
assert_eq!(rb.title, Some("the title".into()));
assert_eq!(rb.url, Some(url));
assert_eq!(rb.sync_status, SyncStatus::New);
assert_eq!(rb.sync_change_counter, 1);
assert_eq!(rb._sync_status, SyncStatus::New);
assert_eq!(rb._sync_change_counter, 1);
assert!(global_change_tracker.changed());
assert_eq!(rb.child_count, 0);

let unfiled = get_raw_bookmark(&conn, &BookmarkRootGuid::Unfiled.as_guid())?
.expect("should get unfiled");
assert_eq!(unfiled.sync_change_counter, 1);
assert_eq!(unfiled._sync_change_counter, 1);

Ok(())
}
Expand Down Expand Up @@ -2101,7 +2096,7 @@ mod tests {
)?;
let bm = get_raw_bookmark(&conn, &guid)?.expect("should exist");
assert_eq!(bm.title, Some("the bookmark".to_string()));
assert_eq!(bm.sync_change_counter, 0);
assert_eq!(bm._sync_change_counter, 0);

// Update to the same value is still not a change.
update_bookmark(
Expand All @@ -2115,7 +2110,7 @@ mod tests {
)?;
let bm = get_raw_bookmark(&conn, &guid)?.expect("should exist");
assert_eq!(bm.title, Some("the bookmark".to_string()));
assert_eq!(bm.sync_change_counter, 0);
assert_eq!(bm._sync_change_counter, 0);

// Update to an empty string sets it to null
update_bookmark(
Expand All @@ -2129,7 +2124,7 @@ mod tests {
)?;
let bm = get_raw_bookmark(&conn, &guid)?.expect("should exist");
assert_eq!(bm.title, None);
assert_eq!(bm.sync_change_counter, 1);
assert_eq!(bm._sync_change_counter, 1);

Ok(())
}
Expand Down Expand Up @@ -2574,15 +2569,15 @@ mod tests {

let bmk = get_raw_bookmark(&conn, &"bookmarkAAAA".into())?
.expect("Should fetch A before resetting");
assert_eq!(bmk.sync_change_counter, 0);
assert_eq!(bmk.sync_status, SyncStatus::Normal);
assert_eq!(bmk._sync_change_counter, 0);
assert_eq!(bmk._sync_status, SyncStatus::Normal);

bookmark_sync::reset(&conn, &EngineSyncAssociation::Disconnected)?;

let bmk = get_raw_bookmark(&conn, &"bookmarkAAAA".into())?
.expect("Should fetch A after resetting");
assert_eq!(bmk.sync_change_counter, 1);
assert_eq!(bmk.sync_status, SyncStatus::New);
assert_eq!(bmk._sync_change_counter, 1);
assert_eq!(bmk._sync_status, SyncStatus::New);

// Ensure we reset Sync metadata, too.
let global = get_meta::<SyncGuid>(&conn, GLOBAL_SYNCID_META_KEY)?;
Expand Down
115 changes: 66 additions & 49 deletions examples/places-autocomplete/src/autocomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,45 @@ struct ImportPlacesOptions {

#[derive(Default, Debug, Clone)]
struct LegacyPlaceVisit {
_id: i64,
date: i64,
visit_type: u8,
_from_visit: i64,
}

#[derive(Default, Debug, Clone)]
struct LegacyPlace {
id: i64,
_guid: String,
url: String,
title: Option<String>,
_title: Option<String>,
_hidden: i64,
_typed: i64,
_last_visit_date: i64,
_visit_count: i64,
_description: Option<String>,
_preview_image_url: Option<String>,
visits: Vec<LegacyPlaceVisit>,
}

impl LegacyPlace {
pub fn from_row(row: &rusqlite::Row<'_>) -> Self {
Self {
id: row.get_unwrap("place_id"),
title: row.get_unwrap("place_title"),
_guid: row.get_unwrap("place_guid"),
_title: row.get_unwrap("place_title"),
url: row.get_unwrap("place_url"),
_description: row.get_unwrap("place_description"),
_preview_image_url: row.get_unwrap("place_preview_image_url"),
_typed: row.get_unwrap("place_typed"),
_hidden: row.get_unwrap("place_hidden"),
_visit_count: row.get_unwrap("place_visit_count"),
_last_visit_date: row.get_unwrap("place_last_visit_date"),
visits: vec![LegacyPlaceVisit {
_id: row.get_unwrap("visit_id"),
date: row.get_unwrap("visit_date"),
visit_type: row.get_unwrap("visit_type"),
_from_visit: row.get_unwrap("visit_from_visit"),
}],
}
}
Expand All @@ -56,7 +74,7 @@ impl LegacyPlace {
VisitTransition::from_primitive(v.visit_type).unwrap_or(VisitTransition::Link),
)
.with_at(types::Timestamp((v.date / 1000) as u64))
.with_title(self.title.clone())
.with_title(self._title.clone())
.with_is_remote(rand::random::<f64>() < options.remote_probability);
places::storage::history::apply_observation_direct(db, obs)?;
}
Expand Down Expand Up @@ -94,29 +112,26 @@ fn import_places(
);
let mut stmt = old.prepare(
"
SELECT
p.id as place_id,
p.guid as place_guid,
p.url as place_url,
p.title as place_title,
p.hidden as place_hidden,
p.typed as place_typed,
p.last_visit_date as place_last_visit_date,
p.visit_count as place_visit_count,
p.description as place_description,
p.preview_image_url as place_preview_image_url,
v.id as visit_id,
v.visit_date as visit_date,
v.visit_type as visit_type,
v.from_visit as visit_from_visit
FROM moz_places p
JOIN moz_historyvisits v
ON p.id = v.place_id
ORDER BY p.id
",
SELECT
p.id as place_id,
p.guid as place_guid,
p.url as place_url,
p.title as place_title,
p.hidden as place_hidden,
p.typed as place_typed,
p.last_visit_date as place_last_visit_date,
p.visit_count as place_visit_count,
p.description as place_description,
p.preview_image_url as place_preview_image_url,
v.id as visit_id,
v.visit_date as visit_date,
v.visit_type as visit_type,
v.from_visit as visit_from_visit
FROM moz_places p
JOIN moz_historyvisits v
ON p.id = v.place_id
ORDER BY p.id
",
)?;

let mut rows = stmt.query(NO_PARAMS)?;
Expand All @@ -140,8 +155,10 @@ fn import_places(
let id: i64 = row.get("place_id")?;
if current_place.id == id {
current_place.visits.push(LegacyPlaceVisit {
_id: row.get("visit_id")?,
date: row.get("visit_date")?,
visit_type: row.get("visit_type")?,
_from_visit: row.get("visit_from_visit")?,
});
continue;
}
Expand Down Expand Up @@ -714,29 +731,29 @@ mod autocomplete {

fn main() -> Result<()> {
let matches = clap::App::new("autocomplete-example")
.arg(clap::Arg::with_name("database_path")
.long("database")
.short("d")
.takes_value(true)
.help("Path to the database (with the *new* schema). Defaults to './new-places.db'"))
.arg(clap::Arg::with_name("import_places")
.long("import-places")
.short("p")
.takes_value(true)
.value_name("'auto'|'path/to/places.sqlite'")
.help("Source places db to import from, or 'auto' to import from the largest places.sqlite"))
.arg(clap::Arg::with_name("import_places_remote_weight")
.long("import-places-remote-weight")
.takes_value(true)
.value_name("WEIGHT")
.help("Probability (between 0.0 and 1.0, default = 0.1) that a given visit from `places` should \
be considered `remote`. Ignored when --import-places is not passed"))
.arg(clap::Arg::with_name("no_interactive")
.long("no-interactive")
.short("x")
.help("Don't run the interactive demo after completion (if you just want to run an \
import and exit, for example)"))
.get_matches();
.arg(clap::Arg::with_name("database_path")
.long("database")
.short("d")
.takes_value(true)
.help("Path to the database (with the *new* schema). Defaults to './new-places.db'"))
.arg(clap::Arg::with_name("import_places")
.long("import-places")
.short("p")
.takes_value(true)
.value_name("'auto'|'path/to/places.sqlite'")
.help("Source places db to import from, or 'auto' to import from the largest places.sqlite"))
.arg(clap::Arg::with_name("import_places_remote_weight")
.long("import-places-remote-weight")
.takes_value(true)
.value_name("WEIGHT")
.help("Probability (between 0.0 and 1.0, default = 0.1) that a given visit from `places` should \
be considered `remote`. Ignored when --import-places is not passed"))
.arg(clap::Arg::with_name("no_interactive")
.long("no-interactive")
.short("x")
.help("Don't run the interactive demo after completion (if you just want to run an \
import and exit, for example)"))
.get_matches();

let db_path = matches
.value_of("database_path")
Expand Down

0 comments on commit 184c70f

Please sign in to comment.