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
Conversation
There was a problem hiding this 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.
@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
There was a problem hiding this 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.
components/push/storage/src/db.rs
Outdated
|
||
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)])?; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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. |
@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. |
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. |
Push now stores
uaid
and the server secretauth
in a table in thepush.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
cargo test --all
produces no test failurescargo clippy --all --all-targets --all-features
runs without emitting any warningscargo fmt
does not produce any changes to the code./gradlew ktlint detekt
runs without emitting any warnings