Gateway crashes when loading alarm journal

I have a gateway that collects quite a few alarms from the factory (it's a process factory where everything is connected so it's all in one project). Using MySQL query I can see the count of alarm_events is around 1 million and alarm_event_data is around 6 million (per month). I have added displayPath filters to reduce the amount of alarms returned (the display path is setup: "department/section/line/machine" and displayPath is then be filtered on a line using "Line1"). When setting the date range to month or year the perspective session becomes unresponsive and after a few seconds the gateway crashes (all other sessions also become unresponsive).

So now the question is, does the search bar affect theSQL query or is it applied to the data returned from the query and is it possible to change the query to limit the rows to be returned to prevent this specific error.

The second question is, the journal pruning works on date range but I would like to prune the alarms on instance count (the count will be changed depending on the priority of the alarm). It is on my todo list to prune this manually with gateway scripting but is this perhaps already a feature?