I have a parser function #lookup that performs a database query, given a string key. When
a wiki page contains {{#lookup:MyKey}}, the callback function looks up the associated
value and uses StripState to place it into the article:
$parser->setFunctionHook('lookup', 'lookupCallback'));
...
function lookupCallback($parser, $key) {
$value = bigDatabaseQuery($key);
return $parser->insertStripItem($value);
}
This works fine, but when there are many #lookup calls on a single wiki page, we are
making many database calls. So I'd like to collect all the keys from all the #lookup
calls and perform a SINGLE database query "where key in ('key1',
'key2', ..., 'keyN')", then call insertStripItem() with each value. I
can't seem to figure out how to architect this.
The callback (lookupCallback) is the ideal place to call insertStripItem with the
looked-up values, since it places the UNIQ string in the right location in the article.
But it also seems to be the only place that I can collect all the keys for performing the
single SQL query. This is a chicken-and-egg problem. I can't seem to do the SQL query
earlier than lookupCallback because if I do, this logic will run even when #lookup is not
present.
Any advice on how to structure this?
Thanks,
DanB