Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Finding parent/grandparent of set item
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1420173095

Message started by Ted Goranson on Jan 1st, 2015, 11:31pm

Title: Finding parent/grandparent of set item
Post by Ted Goranson on 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.

$ExpandoSource

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?

Title: Re: Finding parent/grandparent of set item
Post by Mark Anderson on 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.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.