Notifications and badges

Hi! I need help with making notifications less workload heavy.

I have a header with a notifications icon, showing a badge for the number of unread notifications for events like ‘lesson purchased’. There will be about 10 different types of notification. Currently the badge number is derived from the sum of many separate ‘search for…’ expressions, meaning every time a page is opened, 10 database searches are done, which seems very inefficient.

The badge number:

The database has a Notifications data type, and each notification type is shown in a RG by another search for (a) Recipients contains the current user, and the notification type is not empty.

I don’t think this is the best way, but I don’t know how to do it without using ‘search for…’. Is there a way without searching the database so much?

Thanks!

Why can’t you just do one search? (What’s the point of all those 10 searches?)

2 Likes

Because it was understanding that one search would result in just fewer hits, because it’s the union of all search constraints. But I guess it’s actually the same result, after you made me think about it. Thanks.

1 Like

Also, your notification data type should probably have an Option Set which is the type of notification (Lesson issue, lesson purchased, lesson refund request) etc. Then, have a Transaction field (and fields for any other linked data you need). You’ll find it a lot easier to manage. Generally speaking, if you have to have multiple searches on the same data type or dynamically specify which field to search (which is what you’re doing in your first example), you’re probably doing it wrong.

2 Likes

10 aggregate searches costs exactly 10x more than 1….

So definitely don’t use 10.

3 Likes

I tried your method, and it’s as I first thought - it’s searching for all of those constraints at the same time, not separately, so it never gets any hits. I need it to return the total sum the quantity of each type of notification.

Or you meant something else?

Well surely, the notification wouldn’t exist if all of those fields were empty, so you don’t need to include those constraints at all? So just do a single search for notifications of the current user).

But, if for some reason you do need to do 10 searches, then you can use search 1 merged with search 2 merged with search 3 merged with search 4 etc. and then add :count at the end. (instead of doing each search: count separately)

1 Like

True, I had to check for those other constraints because I didn’t do the delete notification workflows correctly. Now it’s corrected I can just search for the current user:)

1 Like