C
C
checky2015-12-25 10:39:53
PHP
checky, 2015-12-25 10:39:53

How expensive is it to use sql database connections like this?

I am using uikit slideset which will convert html with special attributes to my code
like

<div data-uk-slideset="{default: 4}">
    <ul class="uk-grid uk-slideset">
        <li>...</li>
        <li>...</li>
    </ul>
    <ul class="uk-slideset-nav">...</ul>
</div>

ul class="uk-slideset-nav".../ul after loading the page will no longer contain three dots, but a navigation created depending on the number of li.../li and other js settings in data-uk-
slideset in that I need these elements to appear after clicking on some object on the page, but if I write in jquery something like
$('.myobject').click(function() {
   $(this).html('<div data-uk-slideset="{default: 4}"><ul class="uk-grid uk-slideset"><li>...</li><li>...</li></ul><ul class="uk-slideset-nav">...</ul></div>');
});

then, accordingly, nothing will come
of it, moreover, even if you first run it on some page, and then copy the already redone html code of this slideset and try to add it in the same way via html() to .myobject, then nothing will work either will be ..
the only option is to let the slideset be created on page load in some invisible container, and then move it from there and make it visible, like this:
<div class="myslideset" style="display:none">

<div data-uk-slideset="{default: 4}">
    <ul class="uk-grid uk-slideset">
        <li>...</li>
        <li>...</li>
    </ul>
    <ul class="uk-slideset-nav">...</ul>
</div>

</div>

$('.myobject').click(function() {
   $(this).html( $('.myslideset') ).children('.myslideset').css("display","block");
});

and it works, but it turns out the element is created and pictures are loaded even for those people who do not need it.
But I know what kind of people will need it, because they have a special value in the sql database before that. The bottom line is that let's say this is a super visited site - 100,000 unique per day .. All on one page.
What is better - to check for each page on each page load for the presence of this value through php and only load this slideset, that is:
PHP:
> Connect to the database
> Find out if the person has this value
> If not - nothing, if there is -
echo 'slideset here (also invisible, but when clicked it moves and becomes visible, but images will loadimmediately, before the click )'
> At the end - closing the database
I don't know how resource-intensive it is, but I suppose it's very, (1) if not, then I'll do it.
(2) If yes, then I will not spare people and I will not spare traffic and I will upload these pictures to everyone , even if they never see them.
While writing, I almost definitely decided not to bother and do the (2) way, since in fact I just looked that the pictures there are only 300 kilobytes, especially since they will be cached ..
Therefore, I will repost the question, just for the sake of interest - How costly is it use sql database connections on every page load, if for example the site has 100,000 unique people per day? or if 50,000?)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alex Safonov, 2015-12-25
@checky

But I know what kind of people will need it, because before that they have a special value in the sql database.
In any case, you pull out the authorization data and save it to the session. Joy the flag (UI marker) for displaying the menu.
If you do not have some kind of role/group access model, then create UI markers - what to display for this user.
Of course, the approach decided not to bother has the right to life. But you have to be disciplined.

A
Alexey Ukolov, 2015-12-25
@alexey-m-ukolov

Most likely, you save on matches. Yes, it will eat up some milliseconds of page loading and some kilobytes of memory, but if your server is not running on a wristwatch, you will not notice the difference.
Well, no one forbids caching the value in the session.

D
Dmitry Kovalsky, 2015-12-25
@dmitryKovalskiy

I read a little diagonally, so do not be offended if the advice of the council will echo your outpourings. You have a general list of elements and its subset - a list available to a certain user (by roles or access rights - it doesn't matter). p.1) If these access rights are stored in the database, then just drag from the database only what is potentially necessary for this client. By the way, this data is quite static, so you can safely cache it. p.2) about "only 300kb". Yes, for one user they will be cached, but the first run will be long, but not for another. and with 100k uniks, these 300kb will be given to everyone for the first time, although there is a risk that they are not needed. p.3) Where are these images stored? if in the database, then we again get an extra load on the server for data that it does not need. In my opinion, one of the main rules for such tasks on the load on the database is never drag extra data. Let the base filter them out better than you first dragging a hefty data packet to the application server, then finding out which ones are needed and which are not, then throw all this dump to the client "maybe come in handy."

R
romy4, 2015-12-25
@romy4

> The bottom line is that let's say this is a super visited site - 100,000 unique per day ..
you flatter yourself a lot :)
first make a site, and only then do pointwise optimization of braking queries. now you are not doing that

C
checky, 2015-12-25
@checky

Oh lol .. I came up with the simplest solution for my task - in general, everything will be created when the page loads, it will be hidden, BUT without pictures (empty src) .. just then WHEN CLICKING, the src attribute for all images will change and the desired path will be distributed by id.
But still, the question about databases remains open, I'm just wondering -
How expensive is it to use connections to the sql database on each page load, given the huge number of such downloads per day?
PHP
[connect to db
select values, check
many many code
closing connection] x ~500k-1 million times per day

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question