3 ms·
The old version in arc, mirrored at https://github.com/wting/hackernews/blob/5a3296417d23d1ecc901447af63dfc27af217f40/news.arc#L71 https://github.com/wting/hack
by eesmith 5y ago
The old version in arc, mirrored at https://github.com/wting/hackernews/blob/5a3296417d23d1ecc901447af63dfc27af217f40/news.arc#L71 https://github.com/wting/hackernews/blob/5a3296417d23d1ecc90..., uses the file system as a database.
https://github.com/wting/hackernews/blob/5a3296417d23d1ecc901447af63dfc27af217f40/news.arc#L213 https://github.com/wting/hackernews/blob/5a3296417d23d1ecc90... shows the monotonically increasing number:
(def new-item-id ()
(evtil (++ maxid*) [~file-exists (+ storydir* _)]))
It's used for stories:
(def create-story (url title text user ip)
(newslog ip user 'create url (list title))
(let s (inst 'item 'type 'story 'id (new-item-id)
'url url 'title title 'text text 'by user 'ip ip)
and comments:
(def create-comment (parent text user ip)
(newslog ip user 'comment (parent 'id))
(let c (inst 'item 'type 'comment 'id (new-item-id)
'text text 'parent parent!id 'by user 'ip ip)
No clue how that code structure compares to current implementation. For all I know it's completely different.
- verdverm 5y agoI believe it is still largely filesystem based, so NoSQL?
- throwawayapples 5y agoThanks! That is really interesting. I wonder if it still uses the filesystem as a database (I often do that myself, especially for rarely-read or config data.)
- dusted 5y agoThe filesystem is an excellent database if your queries can be expressed as a path. It's literally what they're made for.. A system for filing information.
- ozzythecat 5y agoAs things are written to file, are they pushed to some cache? I’d imagine we are not reading directly from a disk. Is each HN thread it’s own file? How do we add additional posts into the discussion, maintaining the hierarchy? If each file is a thread, then adding to the discussion means we deserialize the file into memory into some data structure and perform updates in memory? Or is there some syntax that allows us to append to a specific blob/container in the file? Another way could be maybe you have a file and folder per HN thread, and each response and it’s own responses are their own folder and files (recursively). Not sure how performant this would be though.