We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37557
    • 25 Posts
    My problems are maybe related to this thread http://forums.modx.com/thread/72725/feedback-revolution-2-2-0-rc2-with-articles#dis-post-405285 (opened by me). Modx loads very slow (around 6 seks till the tab builds up) I configured my memory_max to 256 mb.

    So what am I doing:

    I have a jqueryUI Tab loading my content from the database related to the starting character from the titel A-Z. This means 26 Tabs. JqueryUI needs a link (with a div) to build the tab. so I have a chunk like this:
    <div id="tabs">
    	<ul><li><a href="[[~65? &searChar=`A`]]">A | </a></li>
    		<li><a href="[[~65? &searChar=`B`]]">B | </a></li> ....
    


    in the resource [[65]] I have this
    [[!getResources:default=`<div style="padding: 10px 0 10px 50px;">Sorry - no books here</div>`? &parents=`66` &tpl=`ajaxTabTmp` &includeTVs=`1` &processTVs=`1` &sortdir=`ASC` &sortby=`menuindex` &limit=`9999` &tvFilters=`title==[[!getURLparam]]%` ]]


    The Filtersnippet [[getURLparam]] is used to get the searchchar out of the URL (A-Z) :

    <?php
    $output = '';
    $output .= $_GET['searChar'];
    return $output;


    The Template ajaxTabTmp builds the content in the Tabs:

    <div class="felder">
          <a href="[[~[[+tv.ID]]]]" titel="[[+tv.title]]">
              <img id="felder" src="[[+tv.titleImg:phpthumbof=`w=120&h=169&zc=1`]]" height="169" width="120" alt="">
          </a>
          <div class="feldertext">
               <a href="[[~[[+tv.ID]]]]" titel="[[+tv.title]]"><div class="uber">[[+tv.title]] </div></a>
               <div class="unter"><a href="[[*site_url]]/authors/[[getResourceField? &id=`[[+tv.authorFirst]]` &field=`alias`]].html">[[getResourceField? &id=`[[+tv.authorFirst]]`]]</div></a>
               <div class="hyphenate text" lang="de">[[+tv.contentDescription:wordTrunc=`100`]]</div></br>
          <!--[[+tv.newBooks]]-->
          </div>
          <div class="preis">Preis: € [[+tv.book_EUR]]  <a class="kaufen" href="[[~[[+tv.ID]]]]">Kaufen</a>
         </div>
    </div>


    It works laugh, but it's slow. I should probably write a xPDO snippet that builds everything together instead of using getResource and getResourceField. But my php knowledge is limited. How could I make this code efficient. How could I optimize caching.
    Thank you for help


    edit: more meaningfull title
    edit: changed misleading sentences



    [ed. note: dreh23 last edited this post 12 years, 4 months ago.]
      • 3749
      • 24,544 Posts
      I think it's the TVs that are taking up most of the time. Anything you can do to reduce the number of TVs in the Tpl chunk will help. It might also help if you didn't need &processTVs. If you can use the raw value of all TVs, you can speed things up by leaving that property out.

      There's also a relatively new getResources property that lets you specify exactly which TVs to include (can't remember the property name offhand). That might help a lot if you have many other TVs besides the ones on the pages in question.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 37557
        • 25 Posts
        ty BoBRay. Turning of TV processing helped quite alot. At least double the speed. Unfortunately I have to convert all pictures to the right size by hand cause phpthumbof wont process. But still site doesn't feel very snappy.
        I'm wondering if this approach using Ressources as a "pseudo-database" and parsing tvs is the right way togo. I have around 100 Items as Ressources (growing) with 15 TVS. I want to display these on several sites customwise with getResources (or anything else). I can't imagine I'm the first one who needs this. Is this the wrong way to go? I have the feeling I misunderstood modx. Could someone explain me please how the standard procedure in a case like this would be. TY for your time.
          • 3749
          • 24,544 Posts
          Your situation is a very common one in MODx. Using Resources to store your data works fine if all your data is text content with some static images. When you try to use that structure for storing other data that doesn't fit in the resource fields, things can get very slow.

          There are some tricks that will speed things up, like not processing the TVs, paring down the getResources tag, preloading the images, etc., but the real solution is to put the data in a custom database table where it belongs. Once the data is in the table (or tables) and you have set them up for xPDO, you can easily create the front-end pages with a custom snippet or the Rowboat extra and one or more custom Tpl chunks.

          If you need a lot of the functionality of resources (e.g., publish dates, unpublish dates, createdon, createdby, published, etc.), you can make your new object a subclass of the modResource class and just add the extra fields you need.

          If you don't need a relational model for your table, and especially if you only need one new table, this might be useful to you: http://bobsguides.com/custom-db-tables.html.

          As an interim solution, you might check out the MIGX package, which allows you to store multiple pieces of data in a single TV. I think it might speed things up considerably, though I don't know if it works well with getResources or not.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 37557
            • 25 Posts
            Thank you Bob for the broad explanation. I used the custom-db-table solution. And it seems it's very speedy. I have a few question I somehow can't figure out.
            Im trying to filter my data where I get all rows where the Title starts with an A B C .....
            <?php
            $output = '';
            
            $_GET['searChar'] = str_replace('>','',$_GET['searChar']);
            $_GET['searChar'] = str_replace('<','',$_GET['searChar']);
            $searChar .= $_GET['searChar'];
            
            /*echo $searChar;*/
            
            $path = MODX_CORE_PATH . 'components/store/';
            $result = $modx->addPackage('store',$path . 'model/','zambon_');
            if (! $result) {
              return 'failed to add package - Yuck - please contact us at the contact page siteadmin@****.net';
            } else {
            $output = '';
            $books = $modx->getCollection('Store', array(  
               'title:LIKE' => '$searChar%'  
            ));
            
            foreach($books as $book) {
                $fields = $book->toArray();
                $output .= $modx->getChunk('ShowAll', $fields);
            }
            return $output;
            }
            


            1. I can't figure out how to filter the title with the variable.
            2. How should I sanityze this proper

            and

            3. What would be the best (easiest) method to give the customer an interface where he can add new books without inventing the wheel.

            Thank you for help -- I really appreciate it.
              • 3749
              • 24,544 Posts
              1. I'm not sure what the form is for that, but I believe it would be:

              'title:LIKE' => $searChar . '%' 


              2. I think MODX and xPDO will sanitize it for you, but I'm not positive.

              3. FormIt with a posthook.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 37557
                • 25 Posts
                1. I tried your solution earlier and it didn't work because I had the wrong template a bit lower laugh.
                So I spend two hours on this mistake => Thats life. For the record now it works with
                'title:LIKE' => $searChar . '%'

                2. next week
                3. next week

                Thank you so far. I hope nothing new comes up.
                  • 37557
                  • 25 Posts
                  I have another question that is just half related to modx. I can't figure out the logic in mysql
                  I wan't to query all the books from the same author. This author is not referenced.
                  Something like this:
                  select all books which have the same authorfield like book with the id="4"

                  Is this a case for getCollectionGraph ?
                  Thank you for help [ed. note: dreh23 last edited this post 12 years, 4 months ago.]
                    • 37557
                    • 25 Posts
                    Talking to myself I got the sql logic
                    select * from store where authorFirst in (select authorFirst from store where id="4")
                      • 37557
                      • 25 Posts
                      Ok last self talking. I got it working. Thanks to everyone involved. --> SOLVED
                      For reference maybe someone finds this usefull
                      <?php
                      $output = '';
                      $bookid .= $_GET['bookid'];
                      /*echo $bookid;*/ 
                      
                      $path = MODX_CORE_PATH . 'components/store/';
                      $result = $modx->addPackage('store',$path . 'model/','zambon_');
                      if (! $result) {
                        return 'failed to add package - Yuck - please contact us at the contact page';
                      } else {
                      
                      /*select * from zambon_store where authorFirst in (select authorFirst from zambon_store where id="4")*/
                      
                      $query = 'SELECT * FROM zambon_store WHERE authorFirst in (select authorFirst from zambon_store where id="'.$bookid.'")';
                      
                      $criteria = new xPDOCriteria($modx, $query);
                      $books = $modx->getCollection('Store', $criteria);
                      
                      foreach($books as $book) {
                          $fields = $book->toArray();
                          $output .= $modx->getChunk('ShowAllTmp', $fields);
                      }
                      return $output;
                      }