Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification count table instead of reading eventlog for new events #26

Open
q2apro opened this issue Aug 26, 2018 · 4 comments
Open

Notification count table instead of reading eventlog for new events #26

q2apro opened this issue Aug 26, 2018 · 4 comments

Comments

@q2apro
Copy link
Owner

q2apro commented Aug 26, 2018

FYI, I am running a quite custom version of the plugin now (even for several websites).

One main difference is that I am tracking all new events in a notification table. So an event is incoming and gets +1 in the notification table. This is for performance since the plugin does only need to check for the notify count in this table. If >0 then display that number in the notification box frontend.

If you are interested, I can try to merge this code into the existing one.

@pupi1985 What do you think? Performance kick needed? :)

@pupi1985
Copy link
Contributor

pupi1985 commented Aug 26, 2018

That's basically a cache. It does help. All you need is a table to store user_id an notification_count. You could use that one to get rid of usermeta. Just make sure you update the count each time a notification is generated an set the primary key as user_id

@q2apro
Copy link
Owner Author

q2apro commented Aug 26, 2018

Yes, I have done all this already. I try to post the code next week. Or directly merge it.
Regards

@q2apro
Copy link
Owner Author

q2apro commented Aug 27, 2018

There are two functions resp. tables defined in qa-plugin.php:

function q2apro_notifycount_increase($userid)
{
	if(!empty($userid))
	{
		qa_db_query_sub('
			INSERT INTO ^notifycount (userid, notifycount) VALUES(#, 1) 
			ON DUPLICATE KEY UPDATE userid = #, notifycount = (notifycount+1)
			',
			$userid, $userid
		);
	}
}

function q2apro_notifycount_nill($userid)
{
	if(!empty($userid))
	{
		qa_db_query_sub('
			INSERT INTO ^notifycount (userid, notifycount) VALUES(#, 0) 
			ON DUPLICATE KEY UPDATE userid = #, notifycount = 0
			',
			$userid, $userid
		);
	}
}

In q2apro-onsitenotifications-event.php (former q2apro-history-check.php), after each:

INSERT INTO ^eventlog

We add:

q2apro_notifycount_increase($uid);

resp.

q2apro_notifycount_increase($pid);

resp.

q2apro_notifycount_increase($userid_CommThr);


In the end of q2apro-onsitenotifications-page.php just before:

exit(); 
} // END AJAX RETURN

We add:

q2apro_notifycount_nill($userid);

That's it.


In q2apro-onsitenotifications-layer.php we use in override of doctype() instead of your $last_visit = $this->getLastVisitForUser($userid); the following:

$eventcount = qa_db_read_one_value(qa_db_query_sub('
				SELECT notifycount FROM ^notifycount
				WHERE userid = #
				',
				$userid
			  ), true);

PS: @pupi1985 I do not like the bracket formating you did in the revised files, the style I am using (gidgreen did too in the end), is much easier to read (bracket on a separate line). Hope you can try this and consider to change. https://softwareengineering.stackexchange.com/q/2715/313824@s And also get rid of the one-if-else-no-bracket-style, I always disliked that. :)

@pupi1985
Copy link
Contributor

Great. Just go ahead an make the changes. BTW, no need to stick to my coding style. I try to adapt to the repository owner coding style when I push, but feel free to make any change. It is your repo at the end of the day.

PS: this is what I use for my projects: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants