]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/be_more_selective_about_running_hooks.mdwn
Linkify URLs.
[ikiwiki.git] / doc / todo / be_more_selective_about_running_hooks.mdwn
1 [[!template  id=gitbranch branch=chrismgray/exclusive-hooks author="[[chrismgray]]"]]
2
3 Sometimes plugins register a function with `hook`, but they only want
4 the function called with the content that they know how to deal with.
5 Normally, this means that they call `pagetype` first thing in the
6 function, determine if they know how to deal with the content, and
7 only do anything if they do.  
8
9 > So, I can't find any plugins shipped with ikiwiki that actually do that.
10 > Scan hooks are only ever passed the content of actual wiki pages, and
11 > so unless a scan hook cares whether a page is written in markdown or
12 > something else, it has no reason to care what the pagetype is. (Same for
13 > linkify.) --[[Joey]]
14
15 This is a bit wasteful in itself, but for external plugins, it's
16 really bad.  For functions like `scan` and `linkify`, where the entire
17 page is sent back and forth over `stdout` and `stdin`, it really slows
18 things down.  
19
20 Thus, I propose that there be a new optional parameter to `hook` that
21 tells it that the function should only be called for files whose type
22 is the same as the id of the plugin calling `hook`.  I have called
23 this parameter `exclusive` in my branch, but this might not be the
24 best name.
25
26 [[!tag patch]]
27
28 > It's an interesting idea, but it might be more useful if it was more
29 > generalized, say, by making it a filter, where the parameter is a regexp.
30
31 > --[[KathrynAndersen]]
32
33 >> Would it make more sense as a pagespec?  That might be a bit more hard
34 >> to implement, but would certainly fix the naming issue.
35 >>
36 >> --[[chrismgray]]
37
38 >>> Considering where it would be called, a pagespec might be overkill. --[[KathrynAndersen]]
39
40 >>>> Pagespecs have some overhead themselves. Probably less than shipping
41 >>>> the page content over stdio.
42 >>>>
43 >>>> Rather than putting filtering in the core of ikiwiki, I can think
44 >>>> of two options. One is to make the main plugin a perl plugin, and
45 >>>> have it call functions that are provided by another, external plugin.
46 >>>> This is assuming you're using the other language because something
47 >>>> is easy to do in it, not to avoid writing perl.
48 >>>> 
49 >>>> Or, the external plugin interface could provide a version of `hook()`
50 >>>> that does not pass the content parameter, but saves a copy that
51 >>>> the plugin could request with a later rpc call. Assuming that
52 >>>> it's really the overhead of serializing the page content, that's
53 >>>> the problem, and not just the general overhead of making rpc calls
54 >>>> for every page.. --[[Joey]]