Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
`tracing-logging` feature and were either also using `tracing-reporting` or not handling error
reporting at all.

### Logins
* Opened count method on logins for Android. ([#7207](https://github.com/mozilla/application-services/pull/7207/))

### Autofill
* Added count methods for credit cards and addresses. ([#7207](https://github.com/mozilla/application-services/pull/7207/))

## ✨ What's New ✨

### Ads Client
Expand Down
6 changes: 6 additions & 0 deletions components/autofill/src/autofill.udl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ interface Store {
[Throws=AutofillApiError]
sequence<CreditCard> get_all_credit_cards();

[Throws=AutofillApiError]
i64 count_all_credit_cards();

[Throws=AutofillApiError]
void update_credit_card(string guid, UpdatableCreditCardFields cc);

Expand All @@ -121,6 +124,9 @@ interface Store {
[Throws=AutofillApiError]
sequence<Address> get_all_addresses();

[Throws=AutofillApiError]
i64 count_all_addresses();

[Throws=AutofillApiError]
void update_address(string guid, UpdatableAddressFields a);

Expand Down
12 changes: 12 additions & 0 deletions components/autofill/src/db/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ pub(crate) fn get_all_addresses(conn: &Connection) -> Result<Vec<InternalAddress
Ok(addresses)
}

pub(crate) fn count_all_addresses(conn: &Connection) -> Result<i64> {
let sql = "SELECT COUNT(*)
FROM addresses_data";

let mut stmt = conn.prepare(sql)?;
let count: i64 = stmt.query_row([], |row| row.get(0))?;
Ok(count)
}

/// Updates just the "updatable" columns - suitable for exposure as a public
/// API.
pub(crate) fn update_address(
Expand Down Expand Up @@ -404,6 +413,9 @@ mod tests {
let expected_number_of_addresses = 2;
assert_eq!(expected_number_of_addresses, retrieved_addresses.len());

let address_count = count_all_addresses(&db).expect("Should count all saved addresses");
assert_eq!(expected_number_of_addresses, address_count as usize);

let retrieved_address_guids = [
retrieved_addresses[0].guid.as_str(),
retrieved_addresses[1].guid.as_str(),
Expand Down
12 changes: 12 additions & 0 deletions components/autofill/src/db/credit_cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ pub(crate) fn get_all_credit_cards(conn: &Connection) -> Result<Vec<InternalCred
Ok(credit_cards)
}

pub(crate) fn count_all_credit_cards(conn: &Connection) -> Result<i64> {
let sql = "SELECT COUNT(*)
FROM credit_cards_data";

let mut stmt = conn.prepare(sql)?;
let count: i64 = stmt.query_row([], |row| row.get(0))?;
Ok(count)
}

pub fn update_credit_card(
conn: &Connection,
guid: &Guid,
Expand Down Expand Up @@ -466,6 +475,9 @@ pub(crate) mod tests {
retrieved_credit_cards.len()
);

let credit_card_count = count_all_credit_cards(&db)?;
assert_eq!(expected_number_of_credit_cards, credit_card_count as usize);

let retrieved_credit_card_guids = [
retrieved_credit_cards[0].guid.as_str(),
retrieved_credit_cards[1].guid.as_str(),
Expand Down
12 changes: 12 additions & 0 deletions components/autofill/src/db/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ impl Store {
Ok(credit_cards)
}

#[handle_error(Error)]
pub fn count_all_credit_cards(&self) -> ApiResult<i64> {
let count = credit_cards::count_all_credit_cards(&self.db.lock().unwrap().writer)?;
Ok(count)
}

#[handle_error(Error)]
pub fn update_credit_card(
&self,
Expand Down Expand Up @@ -136,6 +142,12 @@ impl Store {
Ok(addresses)
}

#[handle_error(Error)]
pub fn count_all_addresses(&self) -> ApiResult<i64> {
let count = addresses::count_all_addresses(&self.db.lock().unwrap().writer)?;
Ok(count)
}

#[handle_error(Error)]
pub fn update_address(&self, guid: String, address: UpdatableAddressFields) -> ApiResult<()> {
addresses::update_address(&self.db.lock().unwrap().writer, &Guid::new(&guid), &address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class DatabaseLoginsStorage(dbPath: String, keyManager: KeyManager) : AutoClosea
return store.list()
}

/**
* Counts the amount of logins.
*
* @return The number of logins.
*/
@Throws(LoginsApiException::class)
fun count(): Long {
return store.count()
}

@Throws(LoginsApiException::class)
fun hasLoginsByBaseDomain(baseDomain: String): Boolean {
return store.hasLoginsByBaseDomain(baseDomain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class DatabaseLoginsStorageTest {
finishAndClose(store)
}

@Test
fun testCount() {
val store = getTestStore()
val count = store.count()
assertEquals(2, count)
finishAndClose(store)
}

@Test
fun testWipeLocal() {
val test = getTestStore()
Expand Down