keWatchMapDB
    :: (Foldable c)
    => c CommentId -> DB (Map CommentId (Set WatchedSubthread))
makeWatchMapDB comment_ids = fmap unwrapTheThings $ do
    ancestral_watches <- select $ from $ \(ws `InnerJoin` ca) -> do
        on_ $ ws ^. WatchedSubthreadRoot ==. ca ^. CommentAncestorAncestor
        where_ $ ca ^. CommentAncestorComment `in_` valList comment_ids
        return (ca ^. CommentAncestorComment, ws)

    current_watches <- select $ from $ \ws -> do
        where_ $ ws ^. WatchedSubthreadRoot `in_` valList comment_ids
        return (ws ^. WatchedSubthreadRoot, ws)

    return $ ancestral_watches <> current_watches

  where
    unwrapTheThings =
        M.fromListWith mappend
        . map (\(Value x, Entity _ y) -> (x, S.singleton y))


makeWatchMapDB
    :: (Foldable c)
    => c CommentId -> DB (Map CommentId (Set WatchedSubthread))
makeWatchMapDB comment_ids = fmap unwrapTheThings $ do
    ancestral_watches <- select $ from $ \(ws `InnerJoin` ca) -> do
        on_ $ ws ^. WatchedSubthreadRoot ==. ca ^. CommentAncestorAncestor
        where_ $ ca ^. CommentAncestorComment `in_` valList comment_ids
        return (ca ^. CommentAncestorComment, ws)

    current_watches <- select $ from $ \ws -> do
        where_ $ ws ^. WatchedSubthreadRoot `in_` valList comment_ids
        return (ws ^. WatchedSubthreadRoot, ws)

    return $ ancestral_watches <> current_watches

  where
    unwrapTheThings =
        M.fromListWith mappend
        . map (\(Value x, Entity _ y) -> (x, S.singleton y))
makeWatchMapDB comment_ids = fmap unwrapTheThings $ do
    ancestral_watches <- select $ from $ \(ws `InnerJoin` ca) -> do
        on_ $ ws ^. WatchedSubthreadRoot ==. ca ^. CommentAncestorAncestor
        where_ $ ca ^. CommentAncestorComment `in_` valList comment_ids
        return (ca ^. CommentAncestorComment, ws)

    current_watches <- select $ from $ \ws -> do
        where_ $ ws ^. WatchedSubthreadRoot `in_` valList comment_ids
        return (ws ^. WatchedSubthreadRoot, ws)

    return $ ancestral_watches <> current_watches

  where
    unwrapTheThings =
        M.fromListWith mappend
        . map (\(Value x, Entity _ y) -> (x, S.singleton y))