(no commit message)
[ikiwiki.git] / 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]] and [[!debbug 544322]]. I'd also like
16 to use it for [[plugins/contrib/album]].
17
18 It could also be used for an [[todo/alias_directive]].
19
20 --[[smcv]]
21
22 > All [[merged|done]] --[[Joey]] 
23
24 --------------------------
25
26 [[!template id=gitbranch branch=smcv/ready/transient author="[[smcv]]"]]
27 [[!tag patch]]
28
29 Related branches:
30
31 * `ready/tag-test`: an extra regression test for tags
32   > merged --[[Joey]] 
33 * either `transient-relative` or `transient-relative-api`: avoid using `Cwd`
34   on initialization
35   > merged the latter --[[Joey]]
36 * `ready/transient-aggregate`: use for aggregate
37   > merged --[[Joey]]
38 * `ready/transient-autoindex`: optionally use for autoindex,
39   which is [[!debbug 544322]] (includes autoindex-autofile from
40   [[todo/autoindex should use add__95__autofile]])
41   > merged. I do note that this interacts badly with ikiwiki-hosting's
42   > backup/restore/branch handling, since that does not back up the
43   > transientdir by default, and so autoindex will not recreate the
44   > "deleted" pages. I'll probably have to make it back up the transientdir
45   > too. --[[Joey]]
46 * `ready/transient-recentchanges`: use for recentchanges
47   > merged --[[Joey]] 
48 * `ready/transient-tag`: optionally use for tag (includes tag-test)
49   > merged --[[Joey]]
50
51 I think this branch is now enough to be useful. It adds the following:
52
53 If the `transient` plugin is loaded, `$srcdir/.ikiwiki/transient` is added
54 as an underlay. I'm not sure whether this should be a plugin or core, so
55 I erred on the side of more plugins; I think it's "on the edge of the core",
56 like goto.
57
58 Pages in the transient underlay are automatically
59 deleted if a page of the same name is created in the srcdir (or an underlay
60 closer to the srcdir in stacking order).
61
62 With the additional `ready/transient-tag` branch,
63 `tag` enables `transient`, and if `tag_autocreate_commit` is set to 0
64 (default 1), autocreated tags are written to the transient underlay.
65 There is a regression test.
66
67 With the additional `transient-autoindex` branch,
68 `autoindex` uses autofiles. It also enables `transient`, and if
69 `autoindex_commit` is set to 0 (default 1), autoindexes are written to
70 the transient underlay. There is a regression test. However, this branch
71 is blocked by working out what the desired behaviour is, on
72 [[todo/autoindex_should_use_add__95__autofile]].
73
74 > I wonder why this needs to be configurable? I suppose that gets back to
75 > whether it makes sense to check these files in or not. The benefits of 
76 > checking them in:
77
78 > * You can edit them from the VCS, don't have to go into the web
79 >   interface. Of course, files from the underlays have a similar issue,
80 >   but does it make sense to make that wart larger?
81 > * You can know you can build the same site with nothing missing
82 >   even if you don't there enable autoindex or whatever. (Edge case.)
83
84 >> I'm not sure that that's a huge wart; you can always "edit by
85 >> overwriting". If you're running a local clone of the wiki on your laptop
86 >> or whatever, you have the underlays already, and can copy from there.
87 >> Tag and autoindex pages have rather simple source code anyway. --s
88
89 > The benefit of using transient pages seems to just be avoiding commit
90 > clutter? For files that are never committed, transient pages are a clear
91 > win, but I wonder if adding configuration clutter just to avoid some 
92 > commit clutter is really worth it.
93
94 >> According to the last section of
95 >> [[todo/auto-create_tag_pages_according_to_a_template]], [[chrysn]] and
96 >> Eric both feel rather strongly that it should be possible to
97 >> not commit any tags; in [[plugins/autoindex/discussion]],
98 >> lollipopman and [[JoeRayhawk]] both requested the same for autoindex.
99 >> I made it configurable because, as you point out,
100 >> there are also reasons why it makes sense to check these
101 >> automatically-created files in. I'm neutral on this, personally.
102 >>
103 >> If this is a point of contention, would you accept a branch that
104 >> just adds `transient` and uses it for [[plugins/recentchanges]],
105 >> which aren't checked in and never have been? I've split the
106 >> branch up in the hope that *some* of it can get merged.
107 >>
108 >>> I will be happy to merge transient-recentchanges when it's ready.
109 >>> I see no obstacle to merging transient-tag either, and am not
110 >>> really against using it for autoindex or aggregate either
111 >>> once they get completed.
112 >>> I just wanted to think through why configurability is needed.
113 >>> --[[Joey]]
114 >>
115 >> One potentially relevant point is that configuration clutter only
116 >> affects the site admin whereas commit clutter is part of the whole
117 >> wiki's history. --[[smcv]]
118
119 > Anyway, the configurability
120 > appears subtly broken; the default is only 1 if a new setup file is
121 > generated. (Correction: It was not even the default then --[[Joey]])
122 > With an existing setup file, the 'default' values in
123 > `getsetup` don't take effect, so it will default to undef, which
124 > is treated the same as 0. --[[Joey]]
125
126 >> Fixed in the branches, hopefully. (How disruptive would it be to have
127 >> defaults take effect whenever the setup file doesn't set a value, btw?
128 >> It seems pretty astonishing to have them work as they do at the moment.) --s
129
130 >>> Well, note that default is not actually a documented field in
131 >>> getsetup hooks at all! (It is used in IkiWiki.pm's own `getsetup()`, and
132 >>> the concept may have leaked out into one or two plugins (comments,
133 >>> transient)).
134 >>> 
135 >>> Running getsetup at plugin load time is something I have considered
136 >>> doing. It would simplify some checkconfig hooks that just set hardcoded 
137 >>> defaults. Although since dying is part of the getsetup hook's API, it
138 >>> could be problimaric.
139 >>> --[[Joey]]
140
141 autoindex ignores pages in the transient underlay when deciding whether
142 to generate an index.
143
144 With the additional `ready/transient-recentchanges` branch, new recent
145 changes go in the transient underlay; I tested this manually.
146
147 Not done yet (in that branch, at least):
148
149 * `remove` can't remove transient pages: this turns out to be harder than
150   I'd hoped, because I don't want to introduce a vulnerability in the
151   non-regular-file detection, so I'd rather defer that.
152
153   > Hmm, I'd at least want that to be dealt with before this was used
154   > by default for autoindex or tag. --[[Joey]]
155
156   >> I'll try to work out which of the checks are required for security
157   >> and which are just nice-to-have, but I'd appreciate any pointers
158   >> you could give. Note that my branch wasn't meant to enable either
159   >> by default, and now hopefully doesn't. --[[smcv]]
160
161   >>> Opened a new bug for this, [[bugs/removal_of_transient_pages]]
162   >>> --[[Joey]] 
163
164 * Transient tags that don't match any pages aren't deleted: I'm not sure
165   that that's a good idea anyway, though. Similarly, transient autoindexes
166   of directories that become empty aren't deleted.
167
168   > Doesn't seem necessary, or really desirable to do that. --[[Joey]]
169
170   >> Good, that was my inclination too. --s
171
172 * In my `untested/transient` branch, new aggregated files go in the
173   transient underlay too (they'll naturally migrate over time). I haven't
174   tested this yet, it's just a proof-of-concept.
175
176   > Now renamed to `ready/transient-aggregate`; it does seem to work fine.
177   > --s
178
179 > I can confirm that the behavior of autoindex, at least, is excellent.
180 > Haven't tried tag. Joey, can you merge transient and autoindex? --JoeRayhawk
181
182 >> Here are some other things I'd like to think about first: --[[Joey]] 
183 >>
184 >> * There's a FIXME in autoindex.
185 >>
186 >>     > Right, the extra logic for preventing autoindex pages from being
187 >>     > re-created. This is taking a while, so I'm going to leave out the
188 >>     > autoindex part for the moment. The FIXME is only relevant
189 >>     > because I tried to solve
190 >>     > [[todo/autoindex should use add__95__autofile]] first, but
191 >>     > strictly speaking, that's an orthogonal change. --s
192
193 >> * Suggest making recentchanges unlink the transient page
194 >>   first, and only unlink from the old location if it wasn't
195 >>   in the transient location. Ok, it only saves 1 syscall :)
196 >>
197 >>   > Is an unlink() really that expensive? But, OK, fixed in the
198 >>   > `ready/transient-recentchanges` branch. --s
199
200 >>   >> It's not, but it's easy. :) --[[Joey]]
201
202 >> * Similarly it's a bit worrying for performance that it
203 >>   needs to pull in and use `Cwd` on every ikiwiki startup now.
204 >>   I really don't see the need; `wikistatedir` should
205 >>   mostly be absolute, and ikiwiki should not chdir in ways
206 >>   that break it anyway.
207 >>
208 >>   > The reason to make it absolute is that relative underlays
209 >>   > are interpreted as relative to the base underlay directory,
210 >>   > not the cwd, by `add_underlay`.
211 >>   >
212 >>   > The updated `ready/transient-only` branch only loads `Cwd` if
213 >>   > the path is relative; an extra commit on branch
214 >>   > `smcv/transient-relative` goes behind `add_underlay`'s
215 >>   > back to allow use of a cwd-relative underlay. Which direction
216 >>   > would you prefer?
217 >>   >
218 >>   > I note in passing that [[plugins/autoindex]] and `IkiWiki::Render`
219 >>   > both need to use `Cwd` and `File::Find` on every refresh, so
220 >>   > there's only any point in avoiding `Cwd` for runs that don't
221 >>   > actually refresh, like simple uses of the CGI. --s
222
223 >>   >> Oh, right, I'd forgotten about the horrificness of File::Find
224 >>   >> that required a chdir for security. Ugh. Can we just avoid
225 >>   >> it for those simple cases then? (demand-calculate wikistatedir)
226 >>   >> --[[Joey]] 
227
228 >>   >>> The reason that transientdir needs to be absolute is that it's
229 >>   >>> added as an underlay.
230 >>   >>>
231 >>   >>> We could avoid using `Cwd` by taking the extra commit from either
232 >>   >>> `smcv/transient-relative` or `smcv/transient-relative-api`;
233 >>   >>> your choice. I'd personally go for the latter.
234 >>   >>>
235 >>   >>> According to git grep, [[plugins/po]] already wants to look at
236 >>   >>> the underlaydirs in its checkconfig hook, so I don't think
237 >>   >>> delaying calculation of the underlaydir is viable. (I also noticed
238 >>   >>> a bug,
239 >>   >>> [[bugs/po:_might_not_add_translated_versions_of_all_underlays]].)
240 >>   >>>
241 >>   >>> `underlaydirs` certainly needs to have been calculated by the
242 >>   >>> time `refresh` hooks finish, so `find_src_files` can use it. --s
243
244 >> * Unsure about the use of `default_pageext` in the `change`
245 >>   hook. Is everything in the transientdir really going
246 >>   to use that pageext? Would it be better to look up the
247 >>   complete source filename?
248 >>
249 >>   > I've updated `ready/transient` to do a more thorough GC by
250 >>   > using File::Find on the transient directory. This does
251 >>   > require `File::Find` and `Cwd`, but only when pages change,
252 >>   > and `refresh` loads both of those in that situation anyway.
253 >>   >
254 >>   > At the moment everything in the transientdir will either
255 >>   > have the `default_pageext` or be internal, although I
256 >>   > did wonder whether to make [[plugins/contrib/album]]
257 >>   > viewer pages optionally be `html`, for better performance
258 >>   > when there's a very large number of photos. --s
259
260 >>   >> Oh, ugh, more File::Find... Couldn't it just assume that the
261 >>   >> transient page has the same extension as its replacement?
262 >>   >> --[[Joey]]
263
264 >>   >>> Good idea, that'll be true for web edits at least.
265 >>   >>> Commit added. --s
266
267 --------------------------
268
269 ## An earlier version
270
271 I had a look at implementing this. It turns out to be harder than I thought
272 to have purely in-memory pages (several plugins want to be able to access the
273 source file as a file), but I did get this proof-of-concept branch
274 to write tag and autoindex pages into an underlay.
275
276 This loses the ability to delete the auto-created pages (although they don't
277 clutter up git this way, at least), and a lot of the code in autoindex is
278 probably now redundant, so this is probably not quite ready for merge, but
279 I'd welcome opinions.
280
281 Usage: set `tag_underlay` and/or `autoindex_underlay` to an absolute path,
282 which you must create beforehand. I suggest *srcdir* + `/.ikiwiki/transient`.
283
284 Refinements that could be made if this approach seems reasonable:
285
286 * make these options boolean, and have the path always be `.ikiwiki/transient`
287 * improve the `remove` plugin so it also deletes from this special underlay
288
289 >> Perhaps it should be something more generic, so that other plugins could use it (such as "album" mentioned above).
290 >> The `.ikiwiki/transient` would suit this, but instead of saying "tag_underlay" or "autoindex_underlay" have "use_transient_underlay" or something like that?
291 >> 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.
292 >> --[[KathrynAndersen]]
293
294 >>> What I had in mind was more like `tag_autocreate_transient => 1` or
295 >>> `autoindex_transient => 1`; you might conceivably want tags to be
296 >>> checked in but autoindices to be transient, and it's fine for each
297 >>> plugin to make its own decision. Going from that to one boolean
298 >>> (or just always-transient if people don't think that's too
299 >>> astonishing) would be trivial, though.
300 >>>
301 >>> I don't think relocating the transient underlay really makes sense,
302 >>> except for prototyping: you only want one, and `.ikiwiki` is as good
303 >>> a place as any (ikiwiki already needs to be able to write there).
304 >>>
305 >>> For [[plugins/contrib/album]] I think I'd just make the photo viewer
306 >>> pages always-transient - you can always make a transient page
307 >>> permanent by editing it, after all.
308 >>>
309 >>> Do you think this approach has enough potential that I should
310 >>> continue to hack on it? Any thoughts on the implementation? --[[smcv]]
311
312 >>>> Ah, now I understand what you're getting at. Yes, it makes sense to put transient pages under `.ikiwiki`.
313 >>>> 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.
314 >>>> 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.
315 >>>>
316 >>>> 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.
317 >>>> 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.
318 >>>> -- [[KathrynAndersen]]