We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: rrswans at Jun 05, 2014, 12:21 AM
    This seems very cool, but is a little over my head. I already have many TV fields that are used in various places throughout my site. These fields already have data. It seems like implementing this will lose that info because everything is moved to another database. Will it change the way the site operates on the front end templates, or in the modx manager? Sorry if this is a stupid question.

    It won't exactly "lose" them. The TV values will still be there, but they won't be stored in the new fields unless you write a utility snippet to read the TVs and write their values to the custom DB fields.

    There's no change in the manager (except the extra fields in the Create/Edit panels), but you do have to modify any templates that use TV tags, and replace any getResources tags that use TVs with a custom snippet.

      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
      • 43957
      • 79 Posts
      Hi all, I too have a site which has crawled to a halt now I have 3000+ resources.

      I've created a Contacts Database Site, but using the MODX addins I know and love, mostly because I was hoping to avoid too much customization.

      Now I think I need to roll up my sleeves and find out how to do this, the question is which is the best way to go?

      Basically, I have a resource for each contact. The user creates and updates from the front end with NewsPublisher. I have many TVs for FirstName, LastName, Phone, Address etc. I also have other resource folders with Companies. I have a resource list TV drop down to link a Contact to a Company resource. The pages render quickly on their own, but it's aggregated content using SiteAtoZ and getresources that takes over 30s to load and the server times out.

      I use SiteAtoZ addin to create an A to Z list of contacts which appears in a menu on every page. I can't take advantage of caching as users regularly update contact details with Newspublisher which clears the cache. I'm pretty sure the cache also needs to clear to update SiteAtoZ if a new Resource/Contact has been added.

      I'd really like to continue using Newspublisher to create and edit, and getresources and SiteAtoZ unless it's really not possible to optimise.

      Have I gone about this the wrong way? Should I somehow create a custom database and have one resource that requests the data and renders the output? I'm not sure where to start with this.

      My other thought is as Bob suggests and extend modresource to include all the fields instead of using TVs. My concern here is will it still be fast enough? Can I still use newspublisher and SiteAtoZ?

      Any suggestions are warmly welcomed
        • 3749
        • 24,544 Posts
        I think NewsPublisher might work if you used the &classKey property in the tag, but I've never tested it.

        SiteAtoZ would not work, but it's *very* slow to begin with. I wrote it a long, long time ago and it actually makes a separate call to getResources for every letter of the alphabet (shudder). I'm a little surprised that you're not getting PHP timeouts.

        If you used ClassExtender to extend modResource, you could use getExtResources to get your display, but that wouldn't get you the A to Z display you have now (unless you called it 26 times wink ). You might be able to replace 'getResources' with 'getExtResources' in the SiteAtoZ snippet code. I think it would work. It would be faster, since you would no longer have any TVs, but I'm not sure by how much.

        It's certainly preferable not to make 26 separate queries to the DB for a single page (or worse -- in your case it may be well over 100 with all the TVs).

        It's a devilish (and interesting) problem. If you extend modResource and you have enough memory and server speed to get all the resources in one query (along with their extended fields), you could make it pretty fast with some custom code.

        Something you could try right now, though, is to add some of the speed-related getResources properties to the AtoZ snippet tag, they will be passed through to getResources. If you can use the raw (rather than processed) values of the TVs (and you probably can), you can use &processTVs=`0`. You can also add &includeTVList=`3,9,22,45` with the IDs of all the TVs you need. That way any other TVs will be ignored.

        It will also help if none of the TVs are set to the default value of the TV and none of them use @ bindings (e.g., @INHERIT). If you give all the TVs a default value of that will never be used (e.g., '---') and never use that value for a TV, they'll be found much faster.

        Another option would be MIGX, but I don't really know how fast it is. It would almost certainly be faster that what you're doing now, because you'd only be getting one TV value per resource, but I don't think it would give you an A to Z listing. I could be wrong.

        I hope this hasn't just made you more confused. 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
          • 33337
          • 3,975 Posts
          In addition to what Bob said above, thats definitely has more weight, but I would like to suggest you to try replacing getResources with pdoResources (part of pdoTools extra) and see if it gives you some speed gain.

          You can also use getCache to utilize timed cache clear instead of clearing cache on every re-save of resources.

          Just my 2 cents.
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 3749
            • 24,544 Posts
            Thanks Zi, I meant to mention pdoResources.

            Randomio is not actually using getResources, though. He or she is using SiteAtoZ, which calls getResources, so the SiteAtoZ snippet code and probably the snippet tag, would have to be modified to use pdoResources.
              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