Android Question Firebase Message token

udg

Expert
Licensed User
Longtime User
Hi all,
in order to send a message to one specific device I tried with the FCM token and it worked flawlessly.
Now, we know that it is good practice not to rely on the FCM mechanism alone, so our app should pull the server in order to request for "recent" messages. The way the pulling is organized depends IMHO on the app's nature.

The question is: given a length of 152 chars (the one I measured) for a token, would it be wiser to index an hash of it on the server so to shorten (hopefully) a query to retrieve recent messages?
I mean, as long as the hash is unique it will behave the same as the more natural indexing on the token itself, but working on a shorter key.
Whenever two distinct tokens could lead to the same hash, the query sub could check the token column against the requested one, so extracting only the expected data.

If you want, my question could be rephrased as: is it advisible to index an hash of the token rather than the token itself?

TIA
 

DonManfred

Expert
Licensed User
Longtime User

The length can be up to 4096 bytes

For me the solution is simple as i only need to maintain about 10 Users/25 Devices in Total which all uses FCM. I know the USER and the Device from any single instance.

Maybe this can help in your hashing:

The hash generated looks like this:
$2a$14$BPHO.gjywGwTOgDt/DbZUelO.6YCjG.3nW10QvCRcBFv4eUHhqIBa
 
  • Like
Reactions: udg
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you Manfred, I didn't know about the 4K possible length for a single token.
So, do you agree with my idea about hashing the token?
I my case it could be expected to have a large number of users/devices.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
At first start of the app generate a unique key. Length is much shorter than 152 Bytes to be unique. So you can identify every device. Store this id as a unique key in a table and the according token. I usually have a sign on in my apps and I update/store the token after login.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thanks. In my case there's no login since it is a totally anonymous service, but I got your point. Being it an hash of the FCM token or a unique key generated upon app first launch, you seem to agree with the "put the index" on a different field rather than on the one storing the token.
Am I right?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Thanks. In my case there's no login since it is a totally anonymous service, but I got your point. Being it an hash of the FCM token or a unique key generated upon app first launch, you seem to agree with the "put the index" on a different field rather than on the one storing the token.
Am I right?

Yes. I often use an own reference to "foreign" data like a customer id to an account number (short and handy).
 
Upvote 0
Top