response
[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 >>> I will be happy to merge transient-recentchanges when it's ready.
87 >>> I see no obstacle to merging transient-tag either, and am not
88 >>> really against using it for autoindex or aggregate either
89 >>> once they get completed.
90 >>> I just wanted to think through why configurability is needed.
91 >>> --[[Joey]]
92 >>
93 >> One potentially relevant point is that configuration clutter only
94 >> affects the site admin whereas commit clutter is part of the whole
95 >> wiki's history. --[[smcv]]
96
97 > Anyway, the configurability
98 > appears subtly broken; the default is only 1 if a new setup file is
99 > generated. (Correction: It was not even the default then --[[Joey]])
100 > With an existing setup file, the 'default' values in
101 > `getsetup` don't take effect, so it will default to undef, which
102 > is treated the same as 0. --[[Joey]]
103
104 >> Fixed in the branches, hopefully. (How disruptive would it be to have
105 >> defaults take effect whenever the setup file doesn't set a value, btw?
106 >> It seems pretty astonishing to have them work as they do at the moment.) --s
107
108 >>> Well, note that default is not actually a documented field in
109 >>> getsetup hooks at all! (It is used in IkiWiki.pm's own `getsetup()`, and
110 >>> the concept may have leaked out into one or two plugins (comments,
111 >>> transient)).
112 >>> 
113 >>> Running getsetup at plugin load time is something I have considered
114 >>> doing. It would simplify some checkconfig hooks that just set hardcoded 
115 >>> defaults. Although since dying is part of the getsetup hook's API, it
116 >>> could be problimaric.
117 >>> --[[Joey]]
118
119 autoindex ignores pages in the transient underlay when deciding whether
120 to generate an index.
121
122 With the additional `ready/transient-recentchanges` branch, new recent
123 changes go in the transient underlay; I tested this manually.
124
125 Not done yet (in that branch, at least):
126
127 * `remove` can't remove transient pages: this turns out to be harder than
128   I'd hoped, because I don't want to introduce a vulnerability in the
129   non-regular-file detection, so I'd rather defer that.
130
131   > Hmm, I'd at least want that to be dealt with before this was used
132   > by default for autoindex or tag. --[[Joey]]
133
134   >> I'll try to work out which of the checks are required for security
135   >> and which are just nice-to-have, but I'd appreciate any pointers
136   >> you could give. Note that my branch wasn't meant to enable either
137   >> by default, and now hopefully doesn't. --[[smcv]]
138
139 * Transient tags that don't match any pages aren't deleted: I'm not sure
140   that that's a good idea anyway, though. Similarly, transient autoindexes
141   of directories that become empty aren't deleted.
142
143   > Doesn't seem necessary, or really desirable to do that. --[[Joey]]
144
145   >> Good, that was my inclination too. --s
146
147 * In my `untested/transient` branch, new aggregated files go in the
148   transient underlay too (they'll naturally migrate over time). I haven't
149   tested this yet, it's just a proof-of-concept.
150
151 > I can confirm that the behavior of autoindex, at least, is excellent.
152 > Haven't tried tag. Joey, can you merge transient and autoindex? --JoeRayhawk
153
154 >> Here are some other things I'd like to think about first: --[[Joey]] 
155 >>
156 >> * There's a FIXME in autoindex.
157 >>
158 >>     > Right, the extra logic for preventing autoindex pages from being
159 >>     > re-created. This is taking a while, so I'm going to leave out the
160 >>     > autoindex part for the moment. The FIXME is only relevant
161 >>     > because I tried to solve
162 >>     > [[todo/autoindex should use add__95__autofile]] first, but
163 >>     > strictly speaking, that's an orthogonal change. --s
164
165 >> * Suggest making recentchanges unlink the transient page
166 >>   first, and only unlink from the old location if it wasn't
167 >>   in the transient location. Ok, it only saves 1 syscall :)
168 >>
169 >>   > Is an unlink() really that expensive? But, OK, fixed in the
170 >>   > `ready/transient-recentchanges` branch. --s
171
172 >>   >> It's not, but it's easy. :) --[[Joey]]
173
174 >> * Similarly it's a bit worrying for performance that it
175 >>   needs to pull in and use `Cwd` on every ikiwiki startup now.
176 >>   I really don't see the need; `wikistatedir` should
177 >>   mostly be absolute, and ikiwiki should not chdir in ways
178 >>   that break it anyway.
179 >>
180 >>   > The reason to make it absolute is that relative underlays
181 >>   > are interpreted as relative to the base underlay directory,
182 >>   > not the cwd, by `add_underlay`.
183 >>   >
184 >>   > The updated `ready/transient-only` branch only loads `Cwd` if
185 >>   > the path is relative; an extra commit on branch
186 >>   > `smcv/transient-relative` goes behind `add_underlay`'s
187 >>   > back to allow use of a cwd-relative underlay. Which direction
188 >>   > would you prefer?
189 >>   >
190 >>   > I note in passing that [[plugins/autoindex]] and `IkiWiki::Render`
191 >>   > both need to use `Cwd` and `File::Find` on every refresh, so
192 >>   > there's only any point in avoiding `Cwd` for runs that don't
193 >>   > actually refresh, like simple uses of the CGI. --s
194
195 >>   >> Oh, right, I'd forgotten about the horrificness of File::Find
196 >>   >> that required a chdir for security. Ugh. Can we just avoid
197 >>   >> it for those simple cases then? (demand-calculate wikistatedir)
198 >>   >> --[[Joey]] 
199
200 >> * Unsure about the use of `default_pageext` in the `change`
201 >>   hook. Is everything in the transientdir really going
202 >>   to use that pageext? Would it be better to look up the
203 >>   complete source filename?
204 >>
205 >>   > I've updated `ready/transient` to do a more thorough GC by
206 >>   > using File::Find on the transient directory. This does
207 >>   > require `File::Find` and `Cwd`, but only when pages change,
208 >>   > and `refresh` loads both of those in that situation anyway.
209 >>   >
210 >>   > At the moment everything in the transientdir will either
211 >>   > have the `default_pageext` or be internal, although I
212 >>   > did wonder whether to make [[plugins/contrib/album]]
213 >>   > viewer pages optionally be `html`, for better performance
214 >>   > when there's a very large number of photos. --s
215
216 >>   >> Oh, ugh, more File::Find... Couldn't it just assume that the
217 >>   >> transient page has the same extension as its replacement?
218 >>   >> --[[Joey]]
219
220 --------------------------
221
222 ## An earlier version
223
224 I had a look at implementing this. It turns out to be harder than I thought
225 to have purely in-memory pages (several plugins want to be able to access the
226 source file as a file), but I did get this proof-of-concept branch
227 to write tag and autoindex pages into an underlay.
228
229 This loses the ability to delete the auto-created pages (although they don't
230 clutter up git this way, at least), and a lot of the code in autoindex is
231 probably now redundant, so this is probably not quite ready for merge, but
232 I'd welcome opinions.
233
234 Usage: set `tag_underlay` and/or `autoindex_underlay` to an absolute path,
235 which you must create beforehand. I suggest *srcdir* + `/.ikiwiki/transient`.
236
237 Refinements that could be made if this approach seems reasonable:
238
239 * make these options boolean, and have the path always be `.ikiwiki/transient`
240 * improve the `remove` plugin so it also deletes from this special underlay
241
242 >> Perhaps it should be something more generic, so that other plugins could use it (such as "album" mentioned above).
243 >> The `.ikiwiki/transient` would suit this, but instead of saying "tag_underlay" or "autoindex_underlay" have "use_transient_underlay" or something like that?
244 >> 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.
245 >> --[[KathrynAndersen]]
246
247 >>> What I had in mind was more like `tag_autocreate_transient => 1` or
248 >>> `autoindex_transient => 1`; you might conceivably want tags to be
249 >>> checked in but autoindices to be transient, and it's fine for each
250 >>> plugin to make its own decision. Going from that to one boolean
251 >>> (or just always-transient if people don't think that's too
252 >>> astonishing) would be trivial, though.
253 >>>
254 >>> I don't think relocating the transient underlay really makes sense,
255 >>> except for prototyping: you only want one, and `.ikiwiki` is as good
256 >>> a place as any (ikiwiki already needs to be able to write there).
257 >>>
258 >>> For [[plugins/contrib/album]] I think I'd just make the photo viewer
259 >>> pages always-transient - you can always make a transient page
260 >>> permanent by editing it, after all.
261 >>>
262 >>> Do you think this approach has enough potential that I should
263 >>> continue to hack on it? Any thoughts on the implementation? --[[smcv]]
264
265 >>>> Ah, now I understand what you're getting at. Yes, it makes sense to put transient pages under `.ikiwiki`.
266 >>>> 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.
267 >>>> 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.
268 >>>>
269 >>>> 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.
270 >>>> 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.
271 >>>> -- [[KathrynAndersen]]