Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: store meta-data for push component in the database. #907

Merged
merged 3 commits into from Apr 10, 2019
Merged

Conversation

jrconlin
Copy link
Contributor

@jrconlin jrconlin commented Apr 3, 2019

Push now stores uaid and the server secret auth in a table in the
push.db. the meta_data table allows any key/value data to be stored to
allow for additional future values (if needed).

Closes #905

Pull Request checklist

  • Quality: This PR builds and tests run cleanly
    • cargo test --all produces no test failures
    • cargo clippy --all --all-targets --all-features runs without emitting any warnings
    • cargo fmt does not produce any changes to the code
    • ./gradlew ktlint detekt runs without emitting any warnings
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due dilligence applied in selecting them.

@jrconlin jrconlin added this to In progress in Push Component Build via automation Apr 3, 2019
components/push/storage/src/schema.sql Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@pjenvey pjenvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't uaid and auth live in the Kotlin side's prefs? On Desktop at least uaid is stored there in dom.push.userAgentID.

What concerns me here is message dispatch (onMessageReceived). When receiving a message dispatch needs to ask Push Storage where to route the message (what uaid and what scope, e.g. FxA related for send tab or normal push messages).

There may be multiple uaids to choose from, either from different gecko profiles or potentially different android users (if we even support the latter?). So as it is currently Push Storage is not per one uaid/profile, it stores all records.

@jrconlin
Copy link
Contributor Author

jrconlin commented Apr 6, 2019

@pjenvey It's my understanding from @jonalmeida that there's no real data storage options for on the Kotlin side. In addition to this, I'm working on a version of Delivery manager that provides a storage mechanism for data associated with the ChannelID.

It's also our understanding that profile changes effectively change all data because they point to a different android data directory. Containers would still use the same UAID, since incoming notifications effectively share the same User Agent.

I also tried to make the meta_data store fairly generic so that if we had to use multiple UAIDs, we could do crap like prefix key names or something.

There still seem to be a lot of unknowns about how User Agents actually will operate and what features we'll be implementing, so simplifying to a base set seemed a better approach than designing for what may not happen.

Push now stores uaid and the server secret auth in a table in the
push.db. the meta_data table allows any key/value data to be stored to
allow for additional future values (if needed).

Closes #905
@jrconlin jrconlin requested a review from thomcc April 8, 2019 21:29
Push Component Build automation moved this from In progress to Needs review Apr 8, 2019
CHANGELOG.md Outdated Show resolved Hide resolved
components/push/communications/src/lib.rs Show resolved Hide resolved
components/push/storage/src/schema.sql Outdated Show resolved Hide resolved
components/push/subscriber/src/lib.rs Outdated Show resolved Hide resolved
components/push/storage/src/db.rs Outdated Show resolved Hide resolved
@jrconlin jrconlin requested a review from thomcc April 9, 2019 15:47
Push Component Build automation moved this from Needs review to Reviewer approved Apr 9, 2019
Copy link
Contributor

@thomcc thomcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay once nits are addressed.


fn set_meta(&self, key: &str, value: &str) -> Result<()> {
let query = "INSERT or REPLACE into meta_data (key, value) values (:k, :v)";
self.execute_named(query, &[(":k", &key), (":v", &value)])?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit execute_named_cached (missed this last time, sorry).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crap, sorry, you're right.

@@ -66,7 +68,15 @@ impl PushManager {
record.app_server_key = self.config.vapid_key.clone();
record.native_id = Some(reg_token);
self.store.put_record(&record)?;
// TODO: just return Record
// store the meta information if we've not yet done that.
if self.store.get_meta("uaid")?.is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we (do we?) have a transaction open here? I guess we only have a single connection, and so it shouldn' tmatter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, there would only be one "uaid". There's been some discussion about how this would be handled by containers (if/when they're brought over to mobile), but even then, having a single UAID may be the answer. UAID is more about delivery to a given device, channel about segregating to recipient processes. Same is true with the registration ID, to an extent, but that's generally initialized at app start and handed to us. The meta data is more a write once, read many store.

);

DROP INDEX IF EXISTS channel_id_idx;
CREATE UNIQUE INDEX channel_id_idx ON push_record(channel_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something, UNIQUE implies the existence of a UNIQUE INDEX, so I don't think we need this.

@thomcc
Copy link
Contributor

thomcc commented Apr 9, 2019

@pjenvey It's my understanding from @jonalmeida that there's no real data storage options for on the Kotlin side.

Is this true? How do we persist the FxA state then?

@jonalmeida
Copy link
Collaborator

@pjenvey It's my understanding from @jonalmeida that there's no real data storage options for on the Kotlin side.

Is this true? How do we persist the FxA state then?

For the UAID, we can persist this but the argument was that, if each client needs to do this, wouldn't it be easier for the rust component to hide that away since it already does that?

For the Delivery Manager request, we have to store our own mapping of service to channelID on each client. Today this is a small list, but it can get quite large as we enable support for web push. For now, we're storing that on the Android side until we get a longer term solution.

@thomcc
Copy link
Contributor

thomcc commented Apr 9, 2019

@jonalmeida Thanks, that makes sense. I agree it's better to persist here (especially since we already have a database to do it in) I was just confused since we were clearly persisting FxA on the android side, which the comment suggested was impossible.

@jrconlin
Copy link
Contributor Author

jrconlin commented Apr 9, 2019

Ah, good. The comment was borne of my own confusion as well. I thought that there was no (or very limited) db like storage available on the client side. My general fear was that I'd be creating a general preference storage system, which I really don't want to do. I'll fix up the comment and follow up with @jonalmeida about this offline.

@jrconlin jrconlin merged commit 570f3fa into master Apr 10, 2019
Push Component Build automation moved this from Reviewer approved to Done Apr 10, 2019
@eoger eoger deleted the bug/905 branch April 10, 2019 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants