Welcome, Guest. Please Login
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
Pages: 1
Send Topic Print
Finding parent/grandparent of set item (Read 1304 times)
Ted Goranson
Full Member

Posts: 141
Virginia Beach VA
Finding parent/grandparent of set item
Jan 1st, 2015, 11:31pm
I'm coming back to coding after a long absence and have forgotten many things. Using v5 here. I have several issues and will break them into separate queries here.

I have a set attribute that lists notes That link inbound with links of a specific type, p_parenthetical.


I will be using the first entry of this set to calculate a badge for the current note; this will also be used for sorting. The location in the outline of that note is significant.

I think this form should do the job. Is this correct?

if((parent($ExpandoSource.at(1))=="Personal Blog"(|(grandparent($ExpandoSource.at(1)))=="Personal Blog"){$Badge="b_4_1redbpe"}

I know the quotes may be curly here.

I have many conditions that need to be considered, including whether $ExpandoSource has more than one item.

Is it more efficient to have deeply nested if statements (with the most likely at the beginning) or to have less nesting but with more complex tests?
Back to top
« Last Edit: Jan 02nd, 2015, 12:10am by Ted Goranson »  
WWW TedGoranson   IP Logged
Mark Anderson
YaBB Administrator

User - not staff!

Posts: 5689
Southsea, UK
Re: Finding parent/grandparent of set item
Reply #1 - Jan 2nd, 2015, 6:57am
I spot one small syntax error:

if((parent($ExpandoSource.at(1))=="Personal Blog"(|(grandparent($ExpandoSource.at(1)))=="Personal Blog"){$Badge="b_4_1redbpe"}

I think the red parenthesis is a posting typo as it should be ')' to close the first condition.

The .at() operator is zero based so $ExpandoSource.at(1) is the second item in the $ExpandoSource list. I assume that is inteneded in the above code.

I would imagine nested 'if' clauses would be more effective as if the most common test comes first fewer tests in aggregate should get run as many tests will complete at the first 'if'.

A pertinent complexity factor is less the overall length of an action but what it does. An action testing a specific attribute is less complex than a test run across all notes using a find() query where the query itself is complex. Regex-based tests like .contains() add to the workload.

I think experience argues that unless an elegant solution is obvious, it is best to let things grow until you're clear there's a bottleneck and then refactor your action code; if necessary, adding new attributes to 'cache' otherwise expensively computed-but-rarely-changing values.
Back to top
« Last Edit: Jan 2nd, 2015, 6:58am by Mark Anderson »  

Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print