parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Provide a way to disable recording PushStatus

Open tobernguyen opened this issue 9 years ago • 13 comments
trafficstars

As I have my own mechanism to log my Push Status so it would be better if we can disable recording PushStatus via Parse Server constructor.

tobernguyen avatar Mar 28 '16 12:03 tobernguyen

The _PushStatus is meant to be used in Parse dashboard. Why would you need to disable it?

flovilmart avatar Mar 28 '16 12:03 flovilmart

As Florent mentioned, this is here to provide support for the dashboard, and it was a requested feature. Not sure why we'd turn this off, but a PR would be reviewed. Thanks.

gfosco avatar Mar 28 '16 22:03 gfosco

I see a point in being able to turn the logging off. It will grow the database by a huge amount if push is used frequently for an app.

ullstrm avatar Apr 10 '16 21:04 ullstrm

I would also like a way to turn off push status or at least a mechanism to clean them after a expire time. this will save lots of db space.

jiawenzhang avatar May 08 '16 21:05 jiawenzhang

you can easily drop the _PushStatus collection right from mongoDB. have a cron that cleanup old data/archive etc...

flovilmart avatar May 08 '16 21:05 flovilmart

I know this bug is rather old but here is a snippet of the cloud code that I'm using to remove _PushStatus entries once the push goes though to avoid growing the collection indefinitely.

Perhaps it will help somebody:

Parse.Cloud.afterSave('_PushStatus', (req, res) => {
    const obj = req.object
    const x = obj.get("status")
    if (x === 'succeeded' || x == 'failed') {
        Parse.Object.destroyAll([obj], {
          success: function() {
          },
          error: function(error) {
            console.log("[afterSave] _PushStatus status '" + x + "' Parse.Object.destroyAll failed with error code: " + error.code)
          },
          useMasterKey: true
       })
    }
});

mman avatar Feb 08 '18 21:02 mman

Well, the biggest reason not to store PushStatus is that sending millions of push notifications at the same time writes millions of rows and gets a lot of unneeded traffic to database.

narekgevorgyan avatar Mar 01 '18 09:03 narekgevorgyan

I’d like to revisit this feature request. My system sends a huge number of push notifications, which leads to the PushStatuses taking up significant database space. I really need a way to disable this logging.

kennic avatar Jul 28 '24 04:07 kennic

A workaround is to set a TTL index (for MongoDB) on the collection. So documents get deleted after a certain amount of time automatically on the DB level, without Parse Server needing to make another request. This is an advantage compared to setting an afterSave trigger.

A solution may be to set a beforeSave trigger, to avoid the document being sent to the DB. I'm not sure whether throwing an error is a way to stop saving the entry, or whether that causes other issues in Parse Server. Would have to try out.

In any case, this is reopened to implement a feature to add a Parse Server config that allows to disable push logging. Also adding a bounty, as this may indeed be a significant performance improvement for apps with high push load.

mtrezza avatar Jul 28 '24 10:07 mtrezza

Thanks for opening this issue!

A workaround is to set a TTL index (for MongoDB) on the collection. So documents get deleted after a certain amount of time automatically on the DB level, without Parse Server needing to make another request. This is an advantage compared to setting an afterSave trigger.

A solution may be to set a beforeSave trigger, to avoid the document being sent to the DB. I'm not sure whether throwing an error is a way to stop saving the entry, or whether that causes other issues in Parse Server. Would have to try out.

In any case, this is reopened to implement a feature to add a Parse Server config that allows to disable push logging. Also adding a bounty, as this may indeed be a significant performance improvement for apps with high push load.

I’m currently using the afterSave trigger to delete _PushStatus. It works, but constantly creating and removing a large number of entities is somewhat wasteful. Having an option to turn this off permanently would be great.

kennic avatar Aug 09 '24 03:08 kennic

Just for completeness... this is the TTL based index that makes it easier to get rid of _PushStatus entries automatically after some time. The key is "expireAfterSeconds" : 300

db.getCollection('_PushStatus').getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_created_at" : 1
		},
		"name" : "_created_at_1",
		"background" : true,
		"expireAfterSeconds" : 300
	},
	{
		"v" : 1,
		"key" : {
			"pushHash" : 1
		},
		"name" : "pushHash_1",
		"background" : true
	},
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_"
	}
]

mman avatar Nov 21 '24 10:11 mman

I wonder how difficult it really is to add an option to disable writing to PushStatus in the first place. Has anyone looked into that? I doubt this is complex. It may impact other features like scheduled push, but that can simply be addressed with a caveat in the docs. The write is really the expensive operation we want to get rid of.

mtrezza avatar Nov 21 '24 17:11 mtrezza