2 ms·
The fnid is the ID of a function. (def morelink (f items label title . args) (tag (a href (url-for (afnid (fn (req)
by jgrahamc 14y ago
The fnid is the ID of a function.
(def morelink (f items label title . args)
(tag (a href
(url-for
(afnid (fn (req)
(prn)
(with (url (url-for it) ; it bound by afnid
user (get-user req))
(newslog req!ip user 'more label)
(longpage user (msec) nil label title url
(apply f user items label title url args))))))
rel 'nofollow)
(pr "More")))
The Hacker News code keeps a table of anonymous functions (see the fn (req) definition there) that can be run later to generate a page. The fnid is the unique ID of that function (which is generated randomly)
(def new-fnid ()
(check (sym (rand-string 10)) ~fns* (new-fnid)))
(def fnid (f)
(atlet key (new-fnid)
(= (fns* key) f)
(push key fnids*)
key))
So, when you hit a URL with a fnid in it the fnid is looked up in the fns* table and the function executed to produce the page. There's a reaper function that deletes fnids that are older than a timeout value (which is how you got the Expired Link error.
(def harvest-fnids ((o n 50000)) ; was 20000
(when (len> fns* n)
(pull (fn ((id created lasts))
(when (> (since created) lasts)
(wipe (fns* id))
t))
timed-fnids*)
(atlet nharvest (trunc (/ n 10))
(let (kill keep) (split (rev fnids*) nharvest)
(= fnids* (rev keep))
(each id kill
(wipe (fns* id)))))))
- kellros 14y agoSo the fnid is essentially a caching mechanism for pre-rendered web pages linked to a point in time? That's pretty neat and simple fitting in perfectly with the simplistic design of HN (not confusing simplistic with basic, instead a reference to the design paradigm).
- brudgers 14y agoMy understanding is that pre-rendered web pages are not involved. What is "cached" is a function whose output is a particular webpage rendered on the fly so that "flag/unflag," current score and number of comments can be kept up to date. In other words, the function fetches a particular group of articles along with the current information about them and generates the page. Some of those articles were known at the time the function was generated. Some of the articles are new or have undergone a significant change in status since the function was generated - I suspect these incur greater overhead. At a certain point, the number of changes are are large enough that it is more efficient to generate a new function.
- zupreme 14y agoThanks for this very detailed response. Is the same FNID shown for all visitors during the FNID's applicable period, or is it individualized or region-specific? Essentially I'm asking if all of us see the same stuff at the same time.