One unnecessary request or everyone in the pupil?



  • Whenever applied, the code checks the user ' s system status (unlocked by the website).

    FIRST:

    One straightforward simple request may be made and the user may be further explained and reported to have been blocked or further developed.


    WTO:

    In the request for, for example, the user ' s info Profile, together with join’s, obtain a systemic user status and first process the status, and then decide what to do with the user and the data obtained in the request.


    First method: Liquidity of implementation, minimization of bd load, economization of baytes (drumbles to kilobaytes, kebait to megabaytes, mgbs to hygigabaytes). Less of the first method: I see only one minus-- an extra staple, not a conject, that's a request for bd.

    I don't see. Moses of second mode: Few complicated queries by bud, a bit Status processing is more difficult (although there is no difficulty in processing status, it is more difficult to obtain this very status from bd). Extra traffic.


    Which means "complication of the code" in the second option: it's necessary to correct, sign, rewrite some of the queries to get user status together with the data.

    And if I follow the first method, I'm only writing one function, and I'm putting DLN on a line to check the dock condition (wheeled) of the client. That's it.


    I'll probably do the first way. Who thinks that?



  • 1 is better.

    Imagine that you have 1,000 different enquiries on the code and have to change your status check:

    Option 1.b: Add kash (memcached/redis/. ♪ .)

    Status to pull out of the cash, and if not, check in the base and pee in the kash.

    When the status of the kash is changed, it is either to lose or to complete the correct data.

    The principle will be similar everywhere:

    <?php
        //http://php.net/manual/en/class.memcache.php
        //get Status
        // Еще важный момент все хранилища плохо работают с `false` поэтому пишите какуюто строку!
        $status = $cache->get('status_' . $user->id);
        if (!$status) {
            $status = $DBAdapter->getStatusFromDB($user->id);
        }
    
    if ($status == 'banned') {
        // Kick user out
    }
    
    
    //update status on user change:
    $user-&gt;save();
    $cache-&gt;set('status_' . $user-&gt;id, $user-&gt;status);
    




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2