2

I need to create some rules like "when create photo, when create video, when create story" but all use the same Event "after content is saved"...

so, what's the best way? a rule that trigger a rule set with various rules or varios indepedent triggered rules?

i.e:

RULE SET

rule (when create content) >
    event (after content is saved) >
        set (set: when create content) >
            rule (when create photo) >
                if:
                do:
                    rule (when create video) >
                        if:
                        do:
                    rule (when create story) >
                        if:
                        do:
                    rule (when create page) >
                        if:
                        do:
                    rule (when create product) >
                        if:
                        do:

total:

1 set
6 rules
1 event

TRIGGERED RULES

Rule (when create photo) >
    Event (after content is saved) >
        if:
        do:

Rule (when create video) >
    Event (after content is saved) >
        if:
        do:

Rule (when create story) >
    Event (after content is saved) >
        if:
        do:

Rule (when create page) >
    Event (after content is saved) >
        if:
        do:

Rule (when create product) >
    Event (after content is saved) >
        if:
        do:

total:

5 rules
5 events

thanks.

2 Answers 2

1

I believe the performance different is marginal, so I would chose the most maintainable.

Anyways in regards to performance my bet would be on the last option. Events function pretty much like a SQL where clause, so having more events doesn't hurt performance in itself. The number of rules that has to be fetched from the database, and initialized does effect performance, along with the number of queries that need to be executed.

So Rules will (most like) in the first case be running two queries. One to get the rule set based in the event and one to get the 5 rules in the set. It will need to instantiate 6 rules classes.

In the second case, rules will run a sigle query and only need to instantiate 5 rules classes.

So with fewer queries and rules classes that need to be instantiated the last version should be the most performance optimized. I doubt that you actually will be able to measure this though.

0

You could also (depending on the complexity of your action) put this inside an extra module like this:

function YOURMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
    if($op == 'insert') {
        $action_types = array('photo','video','story','page','product');
        if(in_array($node->type,$action_types)) {
            // put your action here
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.