some analysis
[ikiwiki] / doc / bugs / trail_excess_dependencies.mdwn
1 I've just modified the trail plugin to use only presence, and not
2 content dependencies. Using content dependencies, particularly to the page
3 that defines the trail, meant that every time that page changed, *every*
4 page in the trail gets rebuilt. This leads to users setting up sites that
5 have horrible performance, if the trail is defined in, for example, the top
6 page of a blog.
7
8 Unfortunatly, this change to presence dependencies has
9 introduced a bug. Now when an existing trail is removed, the pages in the
10 trail don't get rebuilt to remove the trail (both html display and state).
11
12 > Actually, this particular case is usually OK. Suppose a trail `untrail`
13 > contains `untrail/a` (as is the case in the regression
14 > test I'm writing), and you build the wiki, then edit `untrail` to no
15 > longer be a trail, and refresh. `untrail` has changed, so it is
16 > rendered. Assuming that the template of either `untrail` or another
17 > changed page happens to contain the `TRAILS` variable (which is not
18 > guaranteed, but is highly likely), `I::P::t::prerender`
19 > is invoked. It notices that `untrail/a` was previously a trail
20 > member and is no longer, and rebuilds it with the diagnostic
21 > "building untrail/a, its previous or next page has changed".
22
23 > Strictly speaking, I should change `I::P::t::build_affected`
24 > so it calls `prerender`, so we're guaranteed to have done the
25 > recalculation. I'll do that. --[[smcv]]
26
27 I think that to fix this bug, the plugin should use a hook to 
28 force rebuilding of all the pages that were in the trail, when
29 the trail is removed (or changed).
30
31 > The case of "the trail is changed" is still broken:
32 > if the order of items changes, or the trail is removed,
33 > then the logic above means it's OK, but if you
34 > change the `\[[!meta title]]` of the trail, or anything else
35 > used in the prev/up/next bar, the items won't show that
36 > change. --[[smcv]]
37
38 There's a difficulty in doing that: The needsbuild hook runs before the scan
39 hook, so before it has a chance to see if the trail directive is still there.
40 It'd need some changes to ikiwiki's hooks.
41
42 > `build_affected` can fix this, I think. --[[smcv]]
43
44 (An improvement in this area would probably simplify other plugins, which
45 currently abuse the needsbuild hook to unset state, to handle the case
46 where the directive that resulted in that state is removed.)
47
48 I apologise for introducing a known bug, but the dependency mess was too
49 bad to leave as-is. And I have very little time (and regrettably, even less
50 power) to deal with it right now. :( --[[Joey]] 
51
52 > Here is an analysis of how the trail pages interdepend.
53 >
54 > * If *trail* contains a page *member* which does exist, *member* depends
55 >   on *trail*. This is so that if the trail directive is deleted from
56 >   *trail*, or if *trail*'s "friendly" title or trail settings are changed,
57 >   the trail navigation bar in *member* will pick up that change. This is
58 >   now only a presence dependency, which isn't enough to make those happen
59 >   correctly.
60 >
61 > * If *trail* contains consecutive pages *m1* and *m2* in that order,
62 >   *m1* and *m2* depend on each other. This is so that if one's
63 >   "friendly" title changes, the other is rebuilt. This is now only
64 >   a presence dependency, which isn't enough to make those happen
65 >   correctly.
66 >
67 > * If *trail* has *member* in its `pagenames` but there is no page called
68 >   *member*, then *trail* must be rebuilt if *member* is created. This
69 >   was always a presence dependency, and is fine.
70 >
71 > In addition, the `trail` plugin remembers the maps
72 > { trail => next item in that trail } and { trail => previous item in
73 > that trail } for each page. If either changes, the page gets rebuilt
74 > by `build_affected`, with almost the same logic as is used to update
75 > pages that link to a changed page.
76 >
77 > I think it's true to say that the trail always depends on every member,
78 > even if it doesn't display them. This might mean that we can use
79 > "render the trail page" as an opportunity to work out whether any of
80 > its members are also going to need re-rendering?
81 >
82 > --[[smcv]]