Using db data sources


(Alderman) #1

Hi.

 

Does anyone here regularly use db data sources (connected to matrix itself) to pull back and display data that is difficult (or imposible) to do using standard matrix assets?  If so how do these queries measure up performance-wise?

 

Thanks.

 

Jeff.


(Joel Porgand) #2

I use db datasources pretty regularly. Performance for is fine (though I'm sure you could write something that would perform badly if you put your mind to it). It can take a while if you're pulling down a whole lot of results (mostly query time & asset listing rendering time)


(Alderman) #3

Thanks J.P

 

We have a set of a few hundred sidebar items that can be displayed on many pages.  For ease of user maintenance it would be better if the asset ids of the pages they are relevant to were stored in metadata on the sidebar items rather than having to visit each page and insert each one there.  Then when the page is rendered it would need to go and automatically display all the sidebar items relating to itself.

 

Unless I'm thinking about this wrong as regards standard matrix functionality - I wondered whether a db call to return all sidebar items which have the current asset's Id stored in metadata would be the way to go.

 

Our other CMS is Wordpress so we are used to thinking in terms of listing via custom queries.


(Anthony) #4

Could you use an asset list enumerating through all your sidebar items, but with conditional formatting so it only actually printed out the ones that have the relevant entry in the metadata?


(Alderman) #5

Cheers Anthony that's the sort of thing I was trying to get to.  We have loads of asset lists but have not really delved into filtering them.  I presume we would use conditional logic in the formatting to only output details where the current asset's id is contained in the metadata list of linked assets.


(Anthony) #6

Yes. Conditionals can match with regular expressions so can be very flexible. There are other simpler tests available too. Until recently conditionals had to be within a paint layout and that’s the only way I have tried using them but I think in the latest release there is a new option to apply direct to a div


(Joel Porgand) #7

 I wondered whether a db call to return all sidebar items which have the current asset's Id stored in metadata would be the way to go.

 

 

That sounds kinda convoluted. 

 

How many sidebar items can a page have? If you're dealing with a limited number you could try using the related asset field type & give users a few fields to use, then render them out as you see fit. 


(Lcoltman) #8

As an alternate thing to consider:

 

You could replicate this functionality using a search asset instead of an asset listing (although it may be slower than using precooked DB lookups). 

 

Just setup the search to search the metadata field on the sidebars that you're entering all the asset IDs on. Then force the search to use a stored search query based on the current asset ID and set the show results page to Yes (assuming you're embedding the sidebar using a paint layout or deign or something if not you may need to use global keywords). 

 

A couple of things to note:

  • Make sure you have a blank or empty page for no results so that it doesn't appear like a search failed when there's no sidebars
  • If you want the sidebars to appear in some sort of order that may be a little tricky with search but you can probably work out a consistent way to sort via metadata or some other attribute/hackery.
  • You may have to do some tinkering with select metadata fields which do exact matches for search if your asset ID numbers in the system are low and are causing partial matches to come back in your results. ie your sidebars should appear on page 100 and its appearing on asset 1000.

For what its worth you can also use paint layouts to print the results returned in search and asset listings so you can have access to keyword conditionals, in the default format just use: %asset_contents_paint_XXXX%


(Alderman) #9

Thanks for that everyone.  We shall try the conditionals on the output of the asset listing.


(Alderman) #10

ok - this is what we are trying to do..

 

assetID #1 has an asset list nested in it (#2)  the asset list type format default format calls paint layout #3.

 

the condition we are trying to set in the paint layout #3 is this..

 

if asset id #1 (the asset into which the asset listing is nested) existsin the related asset metadata field in asset #2 then output #2's details

 

Does that make any sense?

 

Currently we don't seem to be able to make the paint layout recognise the asset id of #1 - (using globals_asset_assetid)


(Alderman) #11

Ok - all bets are off.  I've just been reminded that these pages are rendered via javascript from a rest asset (with the added complexity of using mustache).  So they aren't 'nested' as such.

 

Thanks everyone anyway.

 

If it had been an ordinary setup we could have set a get variable with the calling asset's id.