about summary refs log tree commit diff
path: root/services/tazblog/src/BlogStore.hs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-08-19T23·17+0100
committerVincent Ambo <tazjin@google.com>2019-08-19T23·17+0100
commit11fcf6229751eb266485cbba78d30aced1787d14 (patch)
tree025f02ca1d1288949f69468e32d9efe795db02a7 /services/tazblog/src/BlogStore.hs
parent1d5b53abf8da7b00ac1e58d43a30f738c157b9d3 (diff)
chore(tazblog): Replace BlogDB with stubs for DNS-based storage r/44
Removes acid-state specific code and the former BlogDB module, in its
stead the new BlogStorage module contains stubs for the functions that
will be filled in with DNS-based storage.

This code is unformatted and will not currently serve a working blog.
Diffstat (limited to 'services/tazblog/src/BlogStore.hs')
-rw-r--r--services/tazblog/src/BlogStore.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/services/tazblog/src/BlogStore.hs b/services/tazblog/src/BlogStore.hs
new file mode 100644
index 0000000000..5ed67ac938
--- /dev/null
+++ b/services/tazblog/src/BlogStore.hs
@@ -0,0 +1,54 @@
+-- |This module implements fetching of individual blog entries from
+-- DNS. Yes, you read that correctly.
+--
+-- Each blog post is stored as a set of records in a designated DNS
+-- zone. For the production blog, this zone is `blog.tazj.in.`.
+--
+-- A top-level record at `_posts` contains a list of all published
+-- post IDs.
+--
+-- For each of these post IDs, there is a record at `_meta.$postID`
+-- that contains the title and number of post chunks.
+--
+-- For each post chunk, there is a record at `_$chunkID.$postID` that
+-- contains a base64-encoded post fragment.
+--
+-- This module implements logic for assembling a post out of these
+-- fragments and caching it based on the TTL of its `_meta` record.
+
+module BlogStore where
+
+import           Data.Text              (Text)
+import Locales (BlogLang(..))
+import           Data.Time (UTCTime)
+import Control.Monad.IO.Class (MonadIO)
+
+newtype EntryId = EntryId { unEntryId :: Integer }
+    deriving (Eq, Ord)
+
+instance Show EntryId where
+  show = show . unEntryId
+
+data Entry = Entry {
+    entryId :: EntryId,
+    lang    :: BlogLang,
+    author  :: Text,
+    title   :: Text,
+    btext   :: Text,
+    mtext   :: Text,
+    edate   :: UTCTime
+} deriving (Eq, Ord, Show)
+
+data BlogCache
+
+type Offset = Integer
+type Count = Integer
+
+newCache :: String -> IO BlogCache
+newCache zone = undefined
+
+listEntries :: MonadIO m => BlogCache -> Offset -> Count -> m [Entry]
+listEntries cache offset count = undefined
+
+getEntry :: MonadIO m => BlogCache -> EntryId -> m (Maybe Entry)
+getEntry cache eId = undefined