updated branches
[ikiwiki] / doc / todo / transient_pages.mdwn
1 On [[todo/auto-create_tag_pages_according_to_a_template]], [[chrysn]]
2 suggests:
3
4 > Instead of creating a file that gets checked in into the RCS, the
5 > source files could be left out and the output files be written as
6 > long as there is no physical source file (think of a virtual underlay).
7 > Something similar would be required to implement alias directive,
8 > which couldn't be easily done by writing to the RCS as the page's
9 > contents can change depending on which other pages claim it as an alias.
10
11 `add_autofile` could be adapted to do this, or a similar API could be
12 added.
13
14 This would also be useful for autoindex, as suggested on
15 [[plugins/autoindex/discussion]]. I'd also like to use it for
16 [[plugins/contrib/album]].
17
18 It could also be used for an [[todo/alias_directive]].
19
20 --[[smcv]]
21
22 --------------------------
23
24 [[!template id=gitbranch branch=smcv/ready/transient author="[[smcv]]"]]
25 [[!template id=gitbranch branch=smcv/ready/transient-recentchanges author="[[smcv]]"]]
26 [[!template id=gitbranch branch=smcv/ready/transient-tag author="[[smcv]]"]]
27 [[!tag patch]]
28
29 I think this branch is now enough to be useful. It adds the following:
30
31 If the `transient` plugin is loaded, `$srcdir/.ikiwiki/transient` is added
32 as an underlay. I'm not sure whether this should be a plugin or core, so
33 I erred on the side of more plugins; I think it's "on the edge of the core",
34 like goto.
35
36 Pages in the transient underlay are automatically
37 deleted if a page of the same name is created in the srcdir (or an underlay
38 closer to the srcdir in stacking order).
39
40 With the additional `ready/transient-tag` branch,
41 `tag` enables `transient`, and if `tag_autocreate_commit` is set to 0
42 (default 1), autocreated tags are written to the transient underlay.
43 There is a regression test.
44
45 With the additional `transient-autoindex` branch,
46 `autoindex` uses autofiles. It also enables `transient`, and if
47 `autoindex_commit` is set to 0 (default 1), autoindexes are written to
48 the transient underlay. There is a regression test. However, this branch
49 is blocked by working out what the desired behaviour is, on
50 [[todo/autoindex_should_use_add__95__autofile]].
51
52 > I wonder why this needs to be configurable? I suppose that gets back to
53 > whether it makes sense to check these files in or not. The benefits of 
54 > checking them in:
55
56 > * You can edit them from the VCS, don't have to go into the web
57 >   interface. Of course, files from the underlays have a similar issue,
58 >   but does it make sense to make that wart larger?
59 > * You can know you can build the same site with nothing missing
60 >   even if you don't there enable autoindex or whatever. (Edge case.)
61
62 >> I'm not sure that that's a huge wart; you can always "edit by
63 >> overwriting". If you're running a local clone of the wiki on your laptop
64 >> or whatever, you have the underlays already, and can copy from there.
65 >> Tag and autoindex pages have rather simple source code anyway. --s
66
67 > The benefit of using transient pages seems to just be avoiding commit
68 > clutter? For files that are never committed, transient pages are a clear
69 > win, but I wonder if adding configuration clutter just to avoid some 
70 > commit clutter is really worth it.
71
72 >> According to the last section of
73 >> [[todo/auto-create_tag_pages_according_to_a_template]], [[chrysn]] and
74 >> Eric both feel rather strongly that it should be possible to
75 >> not commit any tags; in [[plugins/autoindex/discussion]],
76 >> lollipopman and [[JoeRayhawk]] both requested the same for autoindex.
77 >> I made it configurable because, as you point out,
78 >> there are also reasons why it makes sense to check these
79 >> automatically-created files in. I'm neutral on this, personally.
80 >>
81 >> If this is a point of contention, would you accept a branch that
82 >> just adds `transient` and uses it for [[plugins/recentchanges]],
83 >> which aren't checked in and never have been? I've split the
84 >> branch up in the hope that *some* of it can get merged.
85 >>
86 >> One potentially relevant point is that configuration clutter only
87 >> affects the site admin whereas commit clutter is part of the whole
88 >> wiki's history. --[[smcv]]
89
90 > Anyway, the configurability
91 > appears subtly broken; the default is only 1 if a new setup file is
92 > generated. With an existing setup file, the 'default' values in
93 > `getsetup` don't take effect, so it will default to undef, which
94 > is treated the same as 0. --[[Joey]]
95
96 >> Fixed in the branches, hopefully. (How disruptive would it be to have
97 >> defaults take effect whenever the setup file doesn't set a value, btw?
98 >> It seems pretty astonishing to have them work as they do at the moment.) --s
99
100 autoindex ignores pages in the transient underlay when deciding whether
101 to generate an index.
102
103 With the additional `ready/transient-recentchanges` branch, new recent
104 changes go in the transient underlay; I tested this manually.
105
106 Not done yet (in that branch, at least):
107
108 * `remove` can't remove transient pages: this turns out to be harder than
109   I'd hoped, because I don't want to introduce a vulnerability in the
110   non-regular-file detection, so I'd rather defer that.
111
112   > Hmm, I'd at least want that to be dealt with before this was used
113   > by default for autoindex or tag. --[[Joey]]
114
115   >> I'll try to work out which of the checks are required for security
116   >> and which are just nice-to-have, but I'd appreciate any pointers
117   >> you could give. Note that my branch wasn't meant to enable either
118   >> by default, and now hopefully doesn't. --[[smcv]]
119
120 * Transient tags that don't match any pages aren't deleted: I'm not sure
121   that that's a good idea anyway, though. Similarly, transient autoindexes
122   of directories that become empty aren't deleted.
123
124   > Doesn't seem necessary, or really desirable to do that. --[[Joey]]
125
126   >> Good, that was my inclination too. --s
127
128 * In my `untested/transient` branch, new aggregated files go in the
129   transient underlay too (they'll naturally migrate over time). I haven't
130   tested this yet, it's just a proof-of-concept.
131
132 > I can confirm that the behavior of autoindex, at least, is excellent.
133 > Haven't tried tag. Joey, can you merge transient and autoindex? --JoeRayhawk
134
135 >> Here are some other things I'd like to think about first: --[[Joey]] 
136 >>
137 >> * There's a FIXME in autoindex.
138
139 >>> Right, the extra logic for preventing autoindex pages from being
140 >>> re-created. This is taking a while, so I'm going to leave out the
141 >>>> autoindex part for the moment. The FIXME is only relevant
142 >>>> because I tried to solve
143 >>>> [[todo/autoindex should use add__95__autofile]] first, but
144 >>>> strictly speaking, that's an orthogonal change. --s
145
146 >> * Suggest making recentchanges unlink the transient page
147 >>   first, and only unlink from the old location if it wasn't
148 >>   in the transient location. Ok, it only saves 1 syscall :)
149
150 >>> Is an unlink() really that expensive? But, OK, fixed in the
151 >>> `ready/transient-recentchanges` branch. --s
152
153 >> * Similarly it's a bit worrying for performance that it
154 >>   needs to pull in and use `Cwd` on every ikiwiki startup now.
155 >>   I really don't see the need; `wikistatedir` should
156 >>   mostly be absolute, and ikiwiki should not chdir in ways
157 >>   that break it anyway.
158
159 >>> The reason to make it absolute is that relative underlays
160 >>> are interpreted as relative to the base underlay directory,
161 >>> not the cwd, by `add_underlay`.
162 >>>
163 >>> The updated `ready/transient-only` branch only loads `Cwd` if
164 >>> the path is relative; an extra commit on branch
165 >>> `smcv/transient-relative` goes behind `add_underlay`'s
166 >>> back to allow use of a cwd-relative underlay. Which direction
167 >>> would you prefer?
168 >>>
169 >>> I note in passing that [[plugins/autoindex]] and `IkiWiki::Render`
170 >>> both need to use `Cwd` and `File::Find` on every refresh, so
171 >>> there's only any point in avoiding `Cwd` for runs that don't
172 >>> actually refresh, like simple uses of the CGI. --s
173
174 >> * Unsure about the use of `default_pageext` in the `change`
175 >>   hook. Is everything in the transientdir really going
176 >>   to use that pageext? Would it be better to look up the
177 >>   complete source filename?
178
179 >>> I've updated `ready/transient` to do a more thorough GC by
180 >>> using File::Find on the transient directory. This does
181 >>> require `File::Find` and `Cwd`, but only when pages change,
182 >>> and `refresh` loads both of those in that situation anyway.
183 >>>
184 >>> At the moment everything in the transientdir will either
185 >>> have the `default_pageext` or be internal, although I
186 >>> did wonder whether to make [[plugins/contrib/album]]
187 >>> viewer pages optionally be `html`, for better performance
188 >>> when there's a very large number of photos. --s
189
190 --------------------------
191
192 ## An earlier version
193
194 I had a look at implementing this. It turns out to be harder than I thought
195 to have purely in-memory pages (several plugins want to be able to access the
196 source file as a file), but I did get this proof-of-concept branch
197 to write tag and autoindex pages into an underlay.
198
199 This loses the ability to delete the auto-created pages (although they don't
200 clutter up git this way, at least), and a lot of the code in autoindex is
201 probably now redundant, so this is probably not quite ready for merge, but
202 I'd welcome opinions.
203
204 Usage: set `tag_underlay` and/or `autoindex_underlay` to an absolute path,
205 which you must create beforehand. I suggest *srcdir* + `/.ikiwiki/transient`.
206
207 Refinements that could be made if this approach seems reasonable:
208
209 * make these options boolean, and have the path always be `.ikiwiki/transient`
210 * improve the `remove` plugin so it also deletes from this special underlay
211
212 >> Perhaps it should be something more generic, so that other plugins could use it (such as "album" mentioned above).
213 >> The `.ikiwiki/transient` would suit this, but instead of saying "tag_underlay" or "autoindex_underlay" have "use_transient_underlay" or something like that?
214 >> Or to make it more flexible, have just one option "transient_underlay" which is set to an absolute path, and if it is set, then one is using a transient-underlay.
215 >> --[[KathrynAndersen]]
216
217 >>> What I had in mind was more like `tag_autocreate_transient => 1` or
218 >>> `autoindex_transient => 1`; you might conceivably want tags to be
219 >>> checked in but autoindices to be transient, and it's fine for each
220 >>> plugin to make its own decision. Going from that to one boolean
221 >>> (or just always-transient if people don't think that's too
222 >>> astonishing) would be trivial, though.
223 >>>
224 >>> I don't think relocating the transient underlay really makes sense,
225 >>> except for prototyping: you only want one, and `.ikiwiki` is as good
226 >>> a place as any (ikiwiki already needs to be able to write there).
227 >>>
228 >>> For [[plugins/contrib/album]] I think I'd just make the photo viewer
229 >>> pages always-transient - you can always make a transient page
230 >>> permanent by editing it, after all.
231 >>>
232 >>> Do you think this approach has enough potential that I should
233 >>> continue to hack on it? Any thoughts on the implementation? --[[smcv]]
234
235 >>>> Ah, now I understand what you're getting at. Yes, it makes sense to put transient pages under `.ikiwiki`.
236 >>>> I haven't looked at the code, but I'd be interested in seeing whether it's generic enough to be used by other plugins (such as `album`) without too much fuss.
237 >>>> The idea of a transient underlay gives us a desirable feature for free: that if someone edits the transient page, it is made permanent and added to the repository.
238 >>>>
239 >>>> I think the tricky thing with removing these transient underlay pages is the question of how to prevent whatever auto-generated the pages in the first place from generating them again - or, conversely, how to force whatever auto-generated those pages to regenerate them if you've changed your mind.
240 >>>> I think you'd need something similar to `will_render` so that transient pages would be automatically removed if whatever auto-generated them is no longer around.
241 >>>> -- [[KathrynAndersen]]