Description
Issue Description
Right now, when a user reinstalls the app, it creates a new Installation object. It creates duplicates in the database since multiple Installations are now associated with the same user profile.
The old Installations still exist with a valid deviceToken. So when fetching for Installations that matches a list of recipients, the current and old installations are returned, which can result in hundreds of push notifications sent to APNS.
I thought that setting a limit of 10 for the Installation query would help reduce it, but it doesn't seem to affect the number of Installations returned.
Is there a way to avoid the creation of duplicates? And a way to limit the number of results from an Installation request?
Push Configuration
Here is my cloud function to send push notifications :
Parse.Cloud.define("sendPushToRecipients", function(request, response)
{
// Find user profiles from recipients
var profileQuery = new Parse.Query("Profile");
profileQuery.containedIn("objectId", request.params.recipients);
// Find devices associated with the user profiles
var installationQuery = new Parse.Query(Parse.Installation);
installationQuery.matchesQuery("currentProfile", profileQuery);
installationQuery.limit = 10; // not working?
Parse.Push.send({
where: installationQuery,
data: request.params.data
}, {
success: function() {
response.success("Push sent!");
},
error: function(error) {
response.error("Push failed: " + error);
},
useMasterKey: true
});
});
Environment Setup
-
Server
- parse-server version : 2.8.4
- Hardware: Heroku's Standard-1x (512 MB)
- Localhost or remote server? : Heroku
-
Database
- MongoDB version: 4.2.8
- Hardware: Atlas M10
- Localhost or remote server? : MongoDB Atlas
Logs/Trace
2020-07-09T13:21:00.916855+00:00 app[web.2]: Result: "Push sent!" functionName=sendPushToRecipients, recipients=[hRUTEEGIbh], alert=New invite., sound=default, appVersion=636
2020-07-09T13:21:01.074835+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.074909+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.074991+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075069+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075133+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075213+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075278+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075362+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075427+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075502+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075579+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075609+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx
2020-07-09T13:21:01.075699+00:00 app[web.2]: verb parse-server-push-adapter APNS APNS transmitted to xxxx