Queries amount, sessions, empty response

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Queries amount, sessions, empty response

Post by mrgoldy »

Hello hello,

I've been out of the game for a while and have a few question I hope you guys and gals can answer. I've tried (re)searching it beforehand but didn't come to conclusive answers, so here I am.

SQL Queries
How many queries on a single page is considered a lot? I'm currently at around 6 or 7 on the page with the most queries, other pages have less. However, I am not done with coding yet, so I am guessing there will be a few more queries needed that can not be combined (atleast not easily) with the others. I've seen online that it heavily depends on database and server, others say it's better to have a few small ones, so thought I would straight up ask the phpBB community to get a more decisive answer. test anchor link

Language Error
While I love coding with phpBB and the error handling is quite fenomenal and easy to backtrace, it still baffels me that when you forget a single "," at the end of a line in a language file the entire page turns white. Fortunately it's the only error I know that causes this so it's still okay to backtrace. But perhaps a more suitable error handling is possible?

Empty controller response
Is it okay to send a response back like this: return new \Symfony\Component\HttpFoundation\JsonResponse();?
I have an ajaxified rating system I'm working with and everything is handled with, I only need to add something to the database tables, so I need the php file. However, when I just use return; or return 0;, or something similar it gives me an Internal Server Error 500. Adding this empty JsonResponse solves everything. Is this allowed?

Sessions
How long does a user session exactly last? When I'm logged in and I have 'keep me logged in' enabled and come back the next day, am I still on the same session or on a new one? Or only when I'm logged out, either by self-doing or not visiting often enough? Just wondering cause I am storing a cookie per session, check on that cookie and increment a counter.

Sorry for the many questions and thanks in advance,
Kind regards,
Last edited by mrgoldy on Tue Nov 21, 2017 2:08 am, edited 1 time in total.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Queries amount, sessions, empty response

Post by mrgoldy »

Unfortunately no reply yet.


Anyways, I have been reading through a lot of topics on Area51 and reading all the new guidelines on how to use the new text reparser, and I am coding an extension for 3.2.x. Do I use the generate_text_for-line or do I implement the new text_formatter through a service? If the latter, is there a tutorial or an example which I can follow to get a grib on it?

I know the generate_text_for still works, but seeing I am purely coding it for 3.2.x might aswell use the new stuff!
Last edited by mrgoldy on Tue Nov 21, 2017 2:07 am, edited 1 time in total.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Queries amount, sessions, empty response

Post by RMcGirr83 »

You should start a new topic as the two are unrelated.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Queries amount, sessions, empty response

Post by mrgoldy »

Alright, thanks for the heads up. I'll post the text-handling in a seperate topic.

The other questions remain:
- Maximum number of queries per page to strive for
- How to return an empty ajax response?
- When are sessions ended?
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Queries amount, sessions, empty response

Post by david63 »

posey wrote: Wed Nov 15, 2017 3:30 pm Maximum number of queries per page to strive for
If you turn on PHPBB_DISPLAY_LOAD_TIME in your config file you will see how many are running on any page - some vanilla phpBB pages are running over 30. It is not necessarily the number of queries that is the issue but what those queries are doing - you can have 30 queries running in under a second or you could have one query running for several seconds (or if you get your query wrong "minutes"). Then again the server load with running queries will also be dependant on the actual server. Personally I would not worry too much with the number of queries unless it becomes a problem. Depending on what you are doing you could always look at caching the queries.
posey wrote: Wed Nov 15, 2017 3:30 pm How to return an empty ajax response?
Sorry - I have no idea.
posey wrote: Wed Nov 15, 2017 3:30 pm When are sessions ended?
As far as I am aware a session ends when the session length is reached and the user has not been active.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Queries amount, sessions, empty response

Post by RMcGirr83 »

How to return an empty ajax response
Care to expand on what it is you are trying to accomplish? Last I knew you can return a "success" or "error" in ajax...empty, and if was empty what would you do with it, I am not so sure is possible but it depends on what you are trying to accomplish.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Queries amount, sessions, empty response

Post by mrgoldy »

I'm using a 5-star rating system for blogs. A user clicks on one of the stars. The jQuery script changes the display of the stars to the rated score and sends a 'post'-request to the blog controller with an added param ($mode) to get to the correct function. That function adds/updates the ratings table. However, once that is done, it's done. I don't have to return anywhere or route somewhere. So when I just add return; it throws an error of 'no response given'.

script

Code: Select all

(function($) {

'use strict';

$(function() {

	// Set up blog rating
	$('.blog-rating').each(function () {
	    $(this).raty({
			score: function() {
			    return $(this).attr('data-score');
			},
			click: function (score, evt) {
	            $.ajax({
	                type: 'post',
	                url: blogRatingURL,
	                data: {
	                    score: score,
						bid: $('#blog_id').val(),
	                },
	                dataType: 'json'
	            });
				$('.blog-rating').raty('score', score);
	            return false;
	        }
	    });
	});
blog controller file

Code: Select all

	public function misc($blog_id, $mode)
	{
		# Check if Ultimate Blog is enabled and if the user has the 'view' permission
		$this->func->ub_status();

		switch ($mode)
		{
			case 'rate':
				if ($this->request->is_ajax())
				{
					# Check if rating is enabled and user can rate
					if ($this->config['ub_enable_rating'] && $this->auth->acl_get('u_ub_rate'))
					{

						$score_obj = $this->request->variable('score', 0);
						$score = json_decode(htmlspecialchars_decode($score_obj));
						$rating_data = $this->func->rating_add($blog_id, $this->user->data['user_id'], $score);

						# if $rating_added, add it to the LOG
						if ($rating_data['rating_added'])
						{
							$this->log->add('user', $this->user->data['user_id'], $this->user->data['user_ip'], 'ACP_UB_LOG_BLOG_RATED', time(), array($rating_data['blog_title'], $score));
						}
					}

					# Need to return an empty response, otherwise 500 Internal Server error (???)
					return new \Symfony\Component\HttpFoundation\JsonResponse();
				}
			break;
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Queries amount, sessions, empty response

Post by kasimi »

posey wrote: Wed Nov 08, 2017 1:36 pm Adding this empty JsonResponse solves everything. Is this allowed?
Yes, it is indeed required.
posey wrote: Wed Nov 08, 2017 1:36 pm it still baffels me that when you forget a single "," at the end of a line in a language file the entire page turns white
This is not limited to language files. You need to set up your development environment to display errors. Have a look at your php.ini and phpBB's config.php.
Post Reply

Return to “Extension Writers Discussion”