We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7327
    • 195 Posts
    Hi,

    Would anyone know how much resources a typical getResources call takes up? I’m looking into an unconventional way of using it since as of the moment, I haven’t figured out how to use getResources with a page that doesn’t rely on a single loop call, but rather, manually organizing getResource results to a non-linear layout (eg. magazine-like layout). To achieve this, I’ve got 6 uncached getResource calls for a single page. Will I encounter server resource issues with this in the future should this go live?

    Cheers,
    Les
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Could you use one call with a tpl that you can position with css? I’m sure getResources supplies enough placeholders to be able to identify each "block" for the CSS placement.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 22303 MODX Staff
        • 10,725 Posts
        Why does it need to be uncached?
          • 7455
          • 2,204 Posts
          one thing that will speed up is when you are using tv’s but do not need to parse them set parse tv to false. tv parsing takes a lot of cpu and db time

          Dimmy
            follow me on twitter: @dimmy01
            • 7327
            • 195 Posts
            Quote from: sottwell at Jan 03, 2011, 03:07 AM

            Could you use one call with a tpl that you can position with css? I’m sure getResources supplies enough placeholders to be able to identify each "block" for the CSS placement.

            Well that’s what I thought of first, but I don’t know whether it’s possible with GetResources. Rather than relying on TPL to generate an array loop, is there anyway to retrieve a specific result from a getResource call? For example, I only want to retrieve the content and TV information from getResource’s 8th result.

            Quote from: OpenGeek at Jan 03, 2011, 12:09 PM

            Why does it need to be uncached?

            I tried calling them cached, but the result is only from the last getResource call.

            Quote from: Dimmy at Jan 03, 2011, 04:45 PM

            one thing that will speed up is when you are using tv’s but do not need to parse them set parse tv to false. tv parsing takes a lot of cpu and db time

            Dimmy

            I will try disabling TV parsing (though I’ll need to retrieve TVs and content). Update: I’ve disabled TV processing and looks like it still works, but now a little faster smiley.

            To better illustrate what I’m doing, imagine I’ve got the following squares in the page:


            [story_summary_size_1x1][story_summary_size_2x1]
            [story_summary_size_1x1][story_summary_size_1x1][story_summary_size_1x1]
            [[story_summary_size_3x1]
            [story_summary_size_1x1][story_summary_size_1x1][story_summary_size_1x1]

            They’re all pregrouped horizontally.

            I put in child documents within the section that has a radio TV group that lets the user select the type of block size they want the story to appear as (ex. 1x1, 2x1, 3x1).

            I use getResources for each horizontal group and each block size type.

            So to achieve the above:

            [!getResources? filters 1x1 stories with an offset of 0] [!getResources? filters 2x1 stories with an offset of 0]
            [!getResources? filters 1x1 stories with an offset of 1]
            [!getResources? filters 3x1 stories with an offset of 0]
            [!getResources? filters 1x1 stories with an offset of 4]


            Anything else I can use for this sort of scenario? I guess the ability to be able to use the output in a non list-like loop manner is what I’m trying to achieve here.
              • 9102 ☆ A M B ☆
              • 318 Posts
              What distinguishes the size of your stories? Is it stored in a TV? Depending on the details, it might be possible to include the size along with an index number in the id of each div, and then position the stories absolutely according to id using CSS. It’s hard to give more explicit instructions without details, but you might do it something like this:


              • Store the size in a TV
              • Use the "idx" property of GetResources to uniquely identify each story
              • Give each div an id like [[+size]][[+idx]], so each div has a unique id that specifies both the size and the order it appears in
              • Make sure your container div is positioned either absolutely or relatively
              • Give each story div absolute position according to id

              One problem with this, though, is that if the stories are in random order, you may not know what the exact id of each div is going to be. I suppose you could sort them by size, that might help. This also only works if your story boxes are of fixed size. If you want them to be variable height, you’d have to use something even more tricky.

              Maybe another solution would be to create more organization for your stories? For example, you could create three children of your main resource, one for each size. Then make the stories children of these resources according to size. Then use a nested GetResources call, where you call GetResources inside the GetResources template (I’ve done this, it works cached) to get a list of lists of the different sized grandchildren, each with a different template according to size.

              Just brainstorming here, again it’s hard to do more without more detail, but I’m virtually certain there’s some way to do this.
                • 7327
                • 195 Posts

                What distinguishes the size of your stories? Is it stored in a TV?

                Yep.


                Depending on the details, it might be possible to include the size along with an index number in the id of each div, and then position the stories absolutely according to id using CSS. It’s hard to give more explicit instructions without details, but you might do it something like this:

                * Store the size in a TV
                * Use the "idx" property of GetResources to uniquely identify each story
                * Give each div an id like [[+size]][[+idx]], so each div has a unique id that specifies both the size and the order it appears in
                * Make sure your container div is positioned either absolutely or relatively
                * Give each story div absolute position according to id

                Hmm that’s an idea. Is the [+idx] something absolutely unique for each story like a primary key or does the number repeat, dependent on the getResource call (much like a pointer of an array)?

                I initially thought of doing one that has a variable height, but since I’m using a mix of floating and block elements, I thought it wasn’t possible to do a clean layout (there’s a sure chance of frequent encounters with empty blocks). The only story size that can have a variable height is the 3x1 one, since it uses up the entire width of the space.

                Yes, I think it’s also possible to do this without so many calls, but this just means additional computing power.

                I’ve got it working, just trying to find ways of saving getResource calls.

                I’m thinking the most effective way of doing something like this is to be able to retrieve the results of getResource and be able to specifically call up each result in a page template that’s not meant to be used as a repeating pattern (ex. within this template, I want the pagetitle of nth result with a TV var of whatever here).

                Feature request? grin
                  • 22303 MODX Staff
                  • 10,725 Posts
                  This is already implemented by a contributor and has been merged into the latest dev copy of the code for getResources. You will be able to set each Resource as a separate placeholder in the output. I’ll try and get a new version out in the next day or two.
                    • 7327
                    • 195 Posts
                    @Jason

                    Nice! But seriously? Just to see if we’re on the same page, you mean to tell me it’s now possible to use templateitems that have a page template filled with placeholders:

                    If we take something below as the getResource template with the following place holders:

                    [[+getResource_id_1 result_position_1 - pagetitle]]
                    [[+getResource_id_1 result_position_1 - introtext]]
                    [[+getResource_id_1 result_position_1 - content]]

                    [[+getResource_id_1 result_position_3 - pagetitle]]
                    [[+getResource_id_1 result_position_3 - introtext]]
                    [[+getResource_id_1 result_position_3 - content]]

                    [[+getResource_id_1 result_position_5 - pagetitle]]
                    [[+getResource_id_1 result_position_5 - introtext]]
                    [[+getResource_id_1 result_position_5 - content]]

                    [[+getResource_id_1 result_position_8 - pagetitle]]
                    [[+getResource_id_1 result_position_8 - introtext]]
                    [[+getResource_id_1 result_position_8 - content]]

                    Will the above work? And multiple getResource calls work together to fill in the same template?

                    I ask this because I figure there are times when 2 or 3 getResource calls might be needed such as in my problem’s case (a getResource for all 1x1 stories, another for 2x1s, and another for 3x1s)
                      • 9102 ☆ A M B ☆
                      • 318 Posts
                      Modified on further reflection: when you make three separate calls as you describe above, can you call them all cached and get the correct results? Does the problem only occur when you call GetResources cached with the same parameters but different offset? If so, then yeah, go ahead and call GetResources three times at the top of the page and then put in the placeholders wherever you need them.

                      Otherwise, you might be able to do it with a single GetResources call if your template is flexible enough and you can set up some scheme so that you can tell which placeholder is which, perhaps by sorting the stories by size. The If snippet might possibly come in handy in that case as well.