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