I'm new with MySource Matrix and I'm finding system very useful but there is still few things I don't know and I'm desperately looking for an answer:
Is it possible to create something like guest book or section where people could leave their comments. If yes what should i use? I tried asset builder and asset listings but I'm not able to set it up in the way I would like to work.
I'm trying to sort my articles by 'most popular' with depends on how many times the article was reviewed. I can't find any record of it. Is it possible to do that? And what should I use?
MySource Matrix 3.14 (the stable version of which is planned to be release May 7) includes a Comment Asset, as well as the ability to rate these comments which might help you out with the first point.
Point 2 could be done with a trigger on access in theory, but I’m not sure what action you would then perform.
Rating by most popular item is not currently possible, as we don't store any statistics regarding how often an asset is viewed. You would have to write custom code to achieve this.
[quote]Rating by most popular item is not currently possible, as we don’t store any statistics regarding how often an asset is viewed. You would have to write custom code to achieve this.
[right][post=“15687”]<{POST_SNAPBACK}>[/post][/right][/quote]
My question is, is this something Squiz would do, how hard would it be, and what are the likely downsides?
[quote]My question is, is this something Squiz would do, how hard would it be, and what are the likely downsides?
[right][post=“15709”]<{POST_SNAPBACK}>[/post][/right][/quote]
At the moment, its not something we would do natively in Matrix - it requires writing to the database for every single page view, which is far too resource intensive for any high-volume site (and impossible for any site that is front-ended by a Squid caching proxy). We’d then have to change the asset listing (or similar) to be able to sort by page views.
[quote]At the moment, its not something we would do natively in Matrix - it requires writing to the database for every single page view, which is far too resource intensive for any high-volume site (and impossible for any site that is front-ended by a Squid caching proxy). We’d then have to change the asset listing (or similar) to be able to sort by page views.
Having said that, if the views were tracked in a lightweight system running alongside Matrix, how would you sort the items? The only way I can think is print the asset_id to the page (hidden) and then use a really clever bit if javascript to AJAX the results from the other DB, insert the counts to the relevant divs and them!
Or could use a remote datasource to somehow do the reading of the data?
[quote]Having said that, if the views were tracked in a lightweight system running alongside Matrix, how would you sort the items?
[right][post=“15711”]<{POST_SNAPBACK}>[/post][/right][/quote]
You could use the DB Data Source bridge, especially considering we’re adding variables and parameters maps to it soon. It would have to be fairly tightly integrated and I’d need to give it some more thought.
My initial idea is:
Create a trigger action for "Asset Accessed" that writes an entry to the database. Essentially, it should just be a list of Asset IDs.
Create a sort order for asset listings that is essentially a "SELECT assetid, COUNT(assetid) AS count FROM accessed WHERE assetid IN (assets_to_list) ORDERED BY count";
That should be fairly light-weight overall and pretty easy to integrate with Matrix itself.
I agree with Avi on the implementation of this. The one thing I will point out is that I think it would be wise to get Matrix to only record stats for assets you want rather than do filtering in the DB Data Source query. This allows us to make changes to the linking system in Matrix without breaking this setup.
So my very slightly modified idea is to ensure the trigger running on Asset Accessed has trigger conditions applied for location in tree and asset type.
However, having said that, this would make the trigger slower to execute. You'll need to trade that off against the possibility of the DB query breaking in the future.
The other thing to consider is that the asset accessed trigger action will not get executed if Squid is sitting in front of Matrix (like Avi mentioned previously).
If you could find a web stat's package that:[list=1]
uses javascript to record visits
[*]stores its results in a Database
[*]can somehow record the asset id in the db (eg. through a parameter in the javascript)
then you wouldn't have to worry about Squid or load on the Matrix server. If point 3 is not possible via a parameter, could the asset_id be extracted from the web path? I'm guessing you could do it with some tricky SQL, but I haven't used the DataSource Bridge before.
If you can record the full URL (minus the protocol) into a table in the same DB as Matrix, you could easily join that table to the sq_ast_lookup table to determine the asset ID.
If you can use JavaScript with a 3rd Party, you could pass the Asset ID directly to that by using a well-formed URL. You could even do a JavaScript-free "web-bug" version by embedded an <img> tag that has a PHP script as the Image, asking for assetid.jpg.
There are lots of ways to skin this cat, depending on how natively you want to do it with Matrix.
[quote]I agree with Avi on the implementation of this. The one thing I will point out is that I think it would be wise to get Matrix to only record stats for assets you want rather than do filtering in the DB Data Source query.
[right][post=“15713”]<{POST_SNAPBACK}>[/post][/right][/quote]
If the stats table was indexed on asset ID, I reckon it’d be faster to do the filtering on the SELECT query than on the trigger criteria. Though, the trade off would be a very, very large table.
What you should do is a combination: Have the trigger action record asset IDs for every access (INSERT statement). Then have a Cron Job that runs each hour, does a COUNT on each asset ID and writes an individual entry for each asset ID with the total count into another table. Use that table for the SELECT.
[quote]If this can be done without a trigger action, then you don’t have any problems. So triggers do not sound like the right way of doing this.
[right][post=“15720”]<{POST_SNAPBACK}>[/post][/right][/quote]
I actually expected the filtering to be done by custom code and not necessarily the DB Data Source bridge (as that can’t provide a sort order to a Listing Engine asset). Sorry, that wasn’t clear.
I have a prototype of some of our ideas in this thread working – the web-bug stores stats in 0.01 to 0.03 seconds, so it could handle quite a lot of requests per second.
Getting data out of the raw table is pretty quick, but I only have 50 rows so far. Hopefully this weekend I'll load up the table with 500,000+ rows and see what kind of response times I get from the raw table and the calculated table.
This is what my proof-of-concept does/will do:
[Working] There is a Design Area called "stats_bug" that prints an <img> tag. This img tag links to a PHP script on the server that generates a 1x1 pixel gif file (you can even specify the colour!). The real trick is that it stores the asset ID of the currently painted asset in a new sq_stats_raw table (which only has a single column for "assetid").
[To Do] A cron job will scan the sq_stats_raw table and write a unique entry for each asset ID into sq_stats_calc, along with the hit count. This is cumulative on each run.
[To Do] A Popular Asset Listing will work exactly the same as the standard Asset Listing but allow you to sort by popularity (i.e. hits). The sort order will come from sq_stats_calc.
[To Do - Maybe] Create a Statistics Manager System Asset that allows you to reset the hit count for an asset, or a hierarchy or the system.
This code will probably never go into the MySource Matrix core. I just want to make that absolutely clear. :)’ /> I’ll worry about distribution if I ever finish it (my attention span is notoriously short, btw). If anyone who does not have an active Squiz SLA is interested in testing the code, please let me know. If you have an active SLA, this code would void your warranty, which is why I’m excluding you. <img src=‘http://forums.matrix.squiz.net/public/style_emoticons/<#EMO_DIR#>/smile.gif’ class=‘bbc_emoticon’ alt=’
To explain, the code is not likely to go in because the sheer amount of database queries this thing will generate has potential to really cause some problems. Plus, the fact that no other part of Matrix can use this data natively means that you might end up with a few of custom DB data source queries hooked into asset listings or searches, and those queries may break with any major or minor upgrade.
My goal is to create something that can be installed as a package – i.e. a self-contained system that exists outside the core. Hence the new Popular Asset Listing asset, with its own sort-order code.
I'm even considering starting on the the Statistics Manager asset early so that I can allow users to specify a completely different database to use for statistics storage. This could have a much greater impact on performance, as I wouldn't need to use the same user/database as the Matrix data.