We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10355
    • 44 Posts
    Use here is a snippet
    <?php
    c = $modx->newQuery('modResource');
    $c->where(array(
    'deleted' => false,
    'hidemenu' => false,
    'published' => true,
    'createdby' => $modx->user->get('id'),
    ));
    $children = $modx->getChildIds($id);
    if (count($children) > 0) {
    $c->where(array(
    'id:IN' => $children,
    ));
    }
    $c->sortby($sidx, $sord);
    $c->limit($start, $limit);
    $resources = $modx->getCollection('modResource',$c);
    
    // JSON object
    $data->page       = $page;
    $data->total      = $total_pages;
    $data->records    = $count;
    
    $i = 0;
    foreach ($resources as $kamp) {
        $data->rows[$i]['id'] = $kamp->id;
        $data->rows[$i]['cell'] = array(
            $kamp->id,
            $kamp->pagetitle,
            $kamp->content,
            $kamp->getTVValue('exemple1'),
            $kamp->getTVValue('exemple2'),
            $kamp->getTVValue('exemple3'),
            $kamp->getTVValue('exemple4'),
            $kamp->getTVValue('exemple5'),
            );
    
        $i++;
    }
    
    echo json_encode($data);
    ?>
    when adding getTVValue (’exempleX’) then php script execution time increases by several times (the time is very large).
    Without getTVValue (’exempleX’) it works fast.
    Why getTVValue (’’) so slow down?
    What is my mistake?
      • 22303 MODX Staff
      • 10,725 Posts
      Processing Template Variables can be an expensive operation, depending on how complex the processing required to "render" the value is. You’ll have to describe more about those specific Template Variables...
        • 10355
        • 44 Posts
        Template Variables are very simple, they contain only data
        exemple 1 - id of category (int)
        exemple 2 - 11/12/1911 (date)
        exemple 3 - http://google.com (url)
          • 28215
          • 4,149 Posts
          Quote from: G4 at Jan 11, 2011, 10:53 PM

          Template Variables are very simple, they contain only data
          exemple 1 - id of category (int)
          exemple 2 - 11/12/1911 (date)
          exemple 3 - http://google.com (url)

          Not true; they can also contain MODX tags that need to be parsed.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 10355
            • 44 Posts
            Quote from: splittingred at Jan 11, 2011, 11:14 PM

            Not true; they can also contain MODX tags that need to be parsed.
            my data in the TV value do not contain any MODX tags
              • 5253
              • 17 Posts
              although this thread is quite old, I've the same "problem".
              I got a bunch of resources with about 10 TVs for each resource.
              I want to display them in a grid (within a CMP).

              With only a few resources everything works fine, but with some more (tested with 19 resources) the script (via connector.php) becomes very slow (about 6s to load).

              Has anyone an idea how to optimize? I need all the data to update them in a MODx.Window.

              The only idea I got is to put all the TV data (only numbers and strings, no special tags) in one big text TV json encoded. But then I'm unable to edit via resource editing.

              any help appreciated smiley

              thanks a lot and special thanks to splittingred for this great Doodle tutorial laugh
                *there are no strangers - just friends who never met*
                • 3749
                • 24,544 Posts
                Check out the MIGX package, which lets you store multiple values in one TV.

                With respect to the expense of TVs, they are not simple at all. Unlike the resource fields (e.g., content, pagetitle, alias, etc), which come with the page, TV values are stored in two separate tables. To retrieve one TV, MODX has to see if the user has the correct permissions, get the TV object (in order to have the default value) from one table, then get the value of the TV for the current resource from another table, then check both of those for @ bindings and process those, then plug in the default value if the TV is empty for the current resource, then either return the raw value or possibly go through a complex rendering process depending on the type of the TV (and the rendering code is in yet another place).

                Two TVs -- double the time. Ten+ TVs, and you've got a slow page.

                @G4 - BTW, the guy you're arguing about TVs with is the chief architect of MODX. wink
                  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
                  • 5253
                  • 17 Posts
                  thanks a lot for your quick reply!
                  I think I have to re-structure the gallery I'm working on... well... bad luck, but a lot of learnings wink

                  I'll give it a try with Bruno's MIGX. Perhaps it's a possible way to keep the TV editing within a resource. Otherwise I'll use my CMP for editing stuff.

                  thanks and many thanks for your great tutorials @Bob smiley

                  cheers
                    *there are no strangers - just friends who never met*
                    • 12491
                    • 90 Posts
                    I,m stuck with the same problem for months now.

                    Still don't understand why tv's are set so central in modx development while good practice, so it seems, is to avoid them all together. Also i,m a bit disappointed by the fact that the slowness of tv's isn't mentioned anywhere......
                    Something that you would like to know starting making a cms with the framework.

                    My situation:

                    Goal is:

                    tree = menu
                    resource place in tree = resource place in website
                    resource can be a post, a product, a newsitem, a page etc. and holds all necessary value's for it to work.
                    left, righ,t full, portal layout are possible for all resources.
                    As less fields as possible in the manager pages for clients.
                    Only pages that need to be updated by client are in the clients tree.
                    All snippets work in all pages on all levels.
                    two languages

                    Above is done, but on pages with many tv's it's slow, to slow.

                    I have 3 basic templates per context, one home, one for pages one for index-pages.

                    They have 3 tv's regarding layout and function.
                    By selecting chunks in al selectlist you determine the chuncks a chuncklistparser will parse.

                    full/left/right/portal
                    post/page/product/news-item/

                    full/left/right/portal
                    news/blog/catalogue/gallery/and several other like sledded and tabbed content.

                    In the same way there is a possibility to select widgets on either the left or right side.
                    Widgets are basic function blocks like: latest post, submenu, upload files, rss reader, archive, Tagcloud, Taglister, image rotator, search, cart-status, etc.

                    Depending on the function and user (post,page,product,newsitem) (webmaster,client,admin)
                    there are tv's in a cmp. For axample images, links, tags, metatags, prices, product numbers, stock value's, description's, etc


                    99% of the snippets are executed cached, All caching options are on.
                    Only tv's that are needed are proccesed where possible (for example: getresource calls use the tvprocesslist)
                    output of most tv's is set to "string" instead of text or number.
                    Phpthumbof is used for all images and thumbs
                    All packages are latest versions as is Modx: 2.2.0 pl2
                    the errorlog is empty.

                    Stuck with some 300 + chunks, about 100+ snippets and lot's of tv;s i want to ask before refurnishing the hole lot:

                    "Is a MIGX tv with some 40 value's faster as 40 tv's? "

                    Could you think of another way to speed things up?

                    Some other thoughts:
                    Ad fields to the content field table, (but can this be done without causing other probs).
                    make a tv that is an array of value's instead of a single value?
                    a plugin that delays the processing of tv value's untill for instance a ajax script asks for them to be processed

                    Greetings
                    Hurby [ed. note: hurby last edited this post 14 years, 8 months ago.]
                      Sommige mensen hebben aan een half woord genoeg