Child asset count keyword or solution?

Matrix Version: 5.4.5.1

I’m trying to build an asset listing of sites on a server, and looking to output how many child assets each site has.

AFAIK, that’s going to require a second nested asset listing that simply returns the asset count from a listing of the site’s assets.

Does anyone have a better way? The %asset_num_kids% keyword exists for the Asset Map, but doesn’t work in listings…

And is this a new error?

[22-Jul-2019 15:26:19 Pacific/Auckland] PHP Fatal error: Maximum execution time of 60 seconds exceeded in /home/websites/mysource_matrix/packages/cms/listing_engine/listing_engine.inc on line 3148

Not a new error, but that timeout is the reason why “Nested asset listing” doesn’t really work as a way of counting descendent assets. I’m not aware of any programmatic ways to count how many assets are under an asset that are fast enough to be practical.

When I need to check manually, I go to the Permissions screen and acquire the locks to check how many assets would be cascaded to. This is fast-ish (direct query on sq_ast_tree I assume), but I don’t know how you’d go about getting that same info as part of a generated listing (short of using a DB Connection and replicating that query yourself).

Thanks John. Ideally, I want to be able to have this listing available to non technical management in case they want to check numbers provided to them.

I’ve put in a squizmap to make asset_num_kids available, and I’d rather avoid the DB Connection if I could but really need something operational real soon now.

I just realised I may have misread the original question - are you counting direct children or all assets under a site assets?

If you only need direct children, then %asset_children_link_type_1_2^count% should do the job.

The latter unfortunately. Some of the sites are relatively complex, and we’ve had a past problem of people not really grasping how many assets some of our hosted sites contain.

In that case %asset_num_kids% isn’t what you need. In the asset map use case %asset_num_kids% only counts direct children, not all descendants.

You’re probably stuck with trying to make the nested asset listing fast enough to avoid the timeout.

Will “Asset counter report” do the job for you??

https://matrix.squiz.net/manuals/reports/chapters/asset-counter-report

The site asset listing works reliably enough, and without hitting the timeout. The child listing that returns an asset count works well on one site or for a small selection but the number of assets (292K+) on one of our two servers is I think the tipping point - the full combined report is running ok on the server with only ~40k assets.

That report works well to give me a combined total for each server. Per site is a bit more work - we have two servers and the larger server has 150 live sites, which makes running a report for each site a little time consuming. I’m working to reorganise the sites on that server so I can generate totals for sites owned by particular organisational units.

Could the Javascript API be usable for what you want? It has getChildCount and getChildren functions:

https://matrix.squiz.net/manuals/web-services/chapters/javascript-api#getChildCount
https://matrix.squiz.net/manuals/web-services/chapters/javascript-api#getChildren

2 Likes

Resurrecting this thread (hopefully) to ask, if %globals_asset_children_link_type_1^count:[asset#]% will display the number of type 1 kids of the named asset, I’m guessing it will not care about status. Is there something that’ll count type 1 live assets? Manual says no…

Hi @kentst

Depending on what type of asset status you’re trying to exclude, users with different access will get different results from your keyword replacement. A user with admin access will get the count for all assets they have access to, including archived and under construction. A user with read access will get a count for Live, Safe Edit etc.

It’s pretty easy to test this out.

Thanks @MelFreeman. One of the team here reminded me that “public” users will see a count of the live assets only, as that’s all they have permission to see, so %globals_asset_children_link_type_1^count:[asset#]% would work in my use case.

However a colleague also mentioned that %globals_asset_children_link_type_1:<assetid>^as_asset:asset_status_code^contains:16% should work for everyone as status code 16 = live.