Jump to content

Hari KT

Members
  • Posts

    126
  • Joined

  • Last visited

Posts posted by Hari KT

  1. @horst good to hear.

    I have another patch which will more more awesome then . Don't forget to add `private static $mysql_gone = false;` in the `wire/core/DatabaseQuery.php`. And the execute changes to

    public function execute() {
        try {
            $database = $this->wire('database');
            $query = $database->prepare($this->getQuery());
            $result = $query->execute();
            if (self::$mysql_gone) {
                self::$mysql_gone = false;
            }
        } catch (Exception $e) {
            if (self::$mysql_gone) {
                throw new Exception("It is better to exit than throwing error " . $e->getMessage());
            } else {
                // try once again                
                $msg = $e->getMessage();
                if (strstr($msg, 'MySQL server has gone away')) {
                    self::$mysql_gone = true;
                    $database->closePdo();
                    sleep(20);
                    $this->execute();
                } else {
                    throw new Exception($e->getMessage());
                }
            }
        }
        return $query;
    }
    

    Discussion on github https://github.com/ryancramerdesign/ProcessWire/pull/563#issuecomment-50871518

    • Like 1
  2. @horst, so how is things working . I was forced to fix with a different fix again . It was in `DatabaseQuery` execute method.

        public function execute() {
            try {
                $database = $this->wire('database');
                $query = $database->prepare($this->getQuery());
                $query->execute();
            } catch (Exception $e) {
                $msg = $e->getMessage();
                if (strstr($msg, 'MySQL server has gone away')) {
                    $database->closePdo();
                }
                throw new Exception($e->getMessage());
            }
            return $query;
        }
    

    and in the `WireDatabasePdo` adding a new method

        public function closePdo()
        {
            $this->pdo = null;
        }

    Hope this fix will help everyone .
     

    One still problem is one query can be missed which got the failure. To execute that I think it is good to call `execute()` again with some flag set.

    Your thoughts ?

    • Like 2
  3. Hi Ryan,

    I have upgraded to latest version and installing Dynamic module gives me

    Session: Module Auto Install: DynamicRoleSupport - Unable to install module 'DynamicRoleSupport': SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'droles-28' for key 'name_parent_id'

    The 3rd party module was safe this time. Probably because not installed.

  4. I have a module which has dependency on other modules. When upgrading to the latest version on dev branch for testing the latest dynamic roles module. I noticed the module installed got missing.

    It was not shown in installed nor when checked for new modules.

    This is something in the getModuleInfo

    'requires' => array(
    - 'Article',
    - 'Source',
    - 'Section',
    - )

    Other modules don't have any issues. When removing the requires, and deleting the name from modules table I installed a fresh module again.

    When the requires is there and trying to install module it shows module installed with session error unknown.

    Not sure why it is happening.

  5. Hey @tarang9211 ,

    I did looked into the files you have provided.

    You can see already some well written help over https://processwire.com/talk/topic/126-anybody-did-user-registrationlogin/ .

    I assume you are looking for a ajax based user registration. So what you need to do is create a template register.php and do the post validation and return back the response. Depending on response send the user to next page.

    In the register.php template you can validate and create a user via the api something like

    $data = array(
        'username' => 'someone',
        'password' => 'password',
        'email' => 'someone@something.com',
        'fullname' => 'Some One',
    );
    $successflag = true;
    $sql_check = wire('users')->find("email={$data['email']}");
    $messages = array();
    if (count($sql_check)) {
        // user already exists
        $messages[] = array(
            'Email already exists',
        );
        $successflag = false;
    }
    $sql_check = wire('users')->find("name={$data['username']}");            
    if (count($sql_check)) {
        // user already exists
        $messages[] = array(
            'Username already exists',
        );
        $successflag = false;
    }
    if ($successflag) {
        $newuser = new User();
        $newuser->name = $data['username'];
        $newuser->pass = $data['password'];
        $newuser->email = $data['email'];
        $newuser->fullname = $data['fullname'];
        $newuser->roles->add($roles->get("guest"));            
        $newuser->roles->add($roles->get("member"));
        $newuser->save();
    }

    Hope that helps you a bit to start.

    Thanks

  6. Sorry I was a bit late to give you the details on benchmarking.

    Got busy with different stuffs. Here is the code that ran on around 701407 `some-page` and `different-page` of `1158` pages. There is more types of pages, so probably the total of pages will be more.

    <?php
    require dirname(__DIR__) . '/index.php';
    $pages = wire('pages');
    
    $t = Debug::timer();
    $items = $pages->find("template=some-page, limit=1, get_total=count");
    $total = $items->getTotal();
    echo "<p>Found $total some-pages in " . Debug::timer($t) . " seconds using count</p>" . PHP_EOL;
    
    wire('pages')->uncacheAll();
    
    // calculate total using calc method (default)
    $t = Debug::timer();
    $items = $pages->find("template=some-page, limit=1, get_total=calc");
    $total = $items->getTotal();
    echo "<p>Found $total some-pages in " . Debug::timer($t) . " seconds using calc</p>" . PHP_EOL;
    
    wire('pages')->uncacheAll();
    
    $t = Debug::timer();
    $total = $pages->count("template=some-page");
    echo "<p>Found $total some-pages using count() in " . Debug::timer($t) . " seconds using count</p>" . PHP_EOL;
    
    wire('pages')->uncacheAll();
    
    $t = Debug::timer();
    $items = $pages->find("template=different-page, limit=1, get_total=count");
    $total = $items->getTotal();
    echo "<p>Found $total different-pages in " . Debug::timer($t) . " seconds using count</p>" . PHP_EOL;
    
    wire('pages')->uncacheAll();
    
    // calculate total using calc method (default)
    $t = Debug::timer();
    $items = $pages->find("template=different-page, limit=1, get_total=calc");
    $total = $items->getTotal();
    echo "<p>Found $total different-pages in " . Debug::timer($t) . " seconds using calc</p>" . PHP_EOL;
    
    wire('pages')->uncacheAll();
    
    $t = Debug::timer();
    $total = $pages->count("template=different-page");
    echo "<p>Found $total different-page count() in " . Debug::timer($t) . " seconds using count</p>" . PHP_EOL;
    
    wire('pages')->uncacheAll();
    
    $t = Debug::timer();
    $first = $pages->get("template=some-page, sort=-some-page_created");
    echo "<p>Found {$first->title} in " . Debug::timer($t) . " seconds</p>" . PHP_EOL;
    wire('pages')->uncacheAll();
    
    $t = Debug::timer();
    $first = $pages->get("template=some-page, sort=-some-page_created, get_total=0");
    echo "<p>Found {$first->title} with get_total=0 in " . Debug::timer($t) . " seconds</p>" . PHP_EOL;
    wire('pages')->uncacheAll();
    
    

    Result

    <p>Found 701407 some-page in 2.4525 seconds using count</p>
    <p>Found 701407 some-page in 2.7801 seconds using calc</p>
    <p>Found 701407 some-page using count() in 2.6784 seconds using count</p>
    
    <p>Found 1158 different-page in 0.0328 seconds using count</p>
    <p>Found 1158 different-page in 0.0166 seconds using calc</p>
    <p>Found 1158 source count() in 0.0028 seconds using count</p>
    
    <p>Found some title in 3.5964 seconds</p>
    <p>Found some title with get_total=0 in 0.0188 seconds</p>
    

    Indeed the last one has shown a tremendous improvement when kept `get_total=0` .

    Thank you

    • Like 3
  7. Hey,

    I am working on a hook, and when a page is viewed I would like to trigger an event and save something.

    This is my hook

        public function init()
        {
            $this->addHook('Page::loaded', $this, 'pageViewed');
        }
        
        public function pageViewed($event)
        {
            $page = $event->object;
            if ($page->template == 'my-template') {
              // $field = $page->get("article_meta_score");
              // $page->save($field);
              $page->myfieldname = 'Something';
              $page->setOutputFormatting(false);
              $page->save();
              exit;
            }
        }

    Now I am getting

    ( ! ) Fatal error: Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '76021'
    for key 'PRIMARY' (in /var/www/ProcessWire/wire/core/Pages.php line 794)
    #0 /var/www/ProcessWire/wire/core/Pages.php(794): PDOStatement->execute()
    #1 /var/www/ProcessWire/wire/core/Pages.php(716): Pages->savePageQuery(Object(Page), Array)
    #2 [internal function]: Pages->___save(Object(Page), Array)
    #3 /var/www/ProcessWire/wire/core/Wire.php(359): call_user_func_array(Array, Array)
    #4 /var/www/ProcessWire/wire/core/Wire.php(317): Wire->runHooks('save', Array)
    #5 /var/www/ProcessWire/wire/core/Page.php(1121): Wire->__call('save', Array)
    #6 /var/www/ProcessWire/wire/core/Page.php(1121): Pages->save(Object(Page), Array)
    #7 /var/www/ProcessWire/site/modules/SomeModule/SomeModule.module(45): Page->save()
    #8 /var/www/ProcessWire/wire/core/Wire.php(381): SomeModule->pageViewed(Object(HookEvent))
    #9 /var/www/ProcessWire/wire/core/Wire.php(317): Wire->runHooks('loaded', Array)
    #10 /var/www/ProcessWire/wire/core/Page.php(1490) in /var/www/ProcessWire/index.php on line 218

    The page is editable and all. But I am not sure why so.

  8. Hi guys,

    I am experiencing a bit of trouble with the MarkupCache not cached properly. This is the code,

    $cache = wire()->modules->get("MarkupCache");
    if(! $someoperation = $cache->get("someoperation", 60 * 15)) {
        $someoperation = " I am some operation ";  
        if(! $expensive_operation = $cache->get("expensive_operation", 60 * 60 * 24)) {        
            $expensive_operation = " Some expensive operation ";
            $cache->save($expensive_operation);
        }
        $someoperation .= $expensive_operation;
        // I am forced to use the get operation again for I have seen if you are not calling the get the value saved is something else
        $cache->get("someoperation", 0);    
        $cache->save($someoperation);
    }

    Do you guys know what may be the reason the cache could not load ?

    I have tried setting the permission from 766 , 777 etc to the folder site/assets/cache/MarkupCache/ .

    Not saying this doesn't works always but some times espeically before the time expires or when I do a deploy via Jenkins it could not load the data. I can see the file being created, but it is not loading the data.

    What is the use of lastgood file ?

  9. I am here with another issue noticed when running seige to benchmark stuffs.

    There is a bottle neck for SQL_CALC_FOUND_ROWS . I was going through this blog post

    http://www.mysqlperformanceblog.com/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/

    and some of my own tests.

    I am running and testing on ~ 606267 pages.

    SELECT SQL_CALC_FOUND_ROWS * FROM `pages` LIMIT 5

    you will get the result in between ~ 0.42 s to ~ 0.572 s

    When you are running it in two queries, say

    SELECT * FROM `pages` LIMIT 5

    and

    SELECT COUNT(*) FROM `pages`
    

    you will get the result in ~ 0.014 s and 0.189 s respectively.  So a total of ~ 0.203 s.

    So I feel it will be nice not to have the SQL_CALC_FOUND_ROWS always been used when running any queries.

    Some of the additional problems to be taken are the queries will be using joins and those will take more seconds. In my case it has been taking ~22 seconds and more when running.

    Thank you.

    • Like 3
  10. @WillyC I just want to try out whether that will bring any performance improvement when dealing with 1000's of pages.

    I am not sure whether the PW is using an active record or some what similar methodology for saving / updating.

    We will see :)

  11. Hey,

    So this have already been asked by some, and I have noticed your replies that Processwire is very fast, and if not you can cache the results.

    And I agree the same, still I have a question.

    We have around 6,00,000 ( 6 Lakh ) pages, and PW can deliver in ~1.9 to ~4 seconds. ie really awesome thing. One concern is at times it goes slow to ~5 seconds to 8 seconds ( I am talking about onload speed in browser , not the rendering speed ).

    So in my findings the problem is like we have a few cron jobs running via gearman to insert and update certain images and more than that ;) . We are using PW Page api to do the insert / update stuffs. ( May be around a few 1000's of pages are fetched and process at a time ) .

    The question is whether there is a way to get the raw sql queries that we need to run on a single insert / update of a Page . Eg :

    $page = $this->pages->get("id={$data->article_id}");
    if ($page->template == 'something') {
        $date = new DateTime();
        $page->update_field = "Some data"
        $page->save();
    }
    

    So the idea if I know the row sql query to run, we can get and insert via pdo with out the api and see how fast is it processing.

    Let me know if there is a way for the same.

    Also if you have any other suggestions / optimization tips I am Happy to hear and take.

    Thank you.

×
×
  • Create New...