Sync starts by getting latest post for each board
This commit is contained in:
parent
518467c7eb
commit
1113539321
|
@ -80,6 +80,7 @@ executable chan-delorean
|
||||||
Data.WordUtil
|
Data.WordUtil
|
||||||
Network.DataClient
|
Network.DataClient
|
||||||
Network.DataClientTypes
|
Network.DataClientTypes
|
||||||
|
Network.GetLatestPostsPerBoardResponse
|
||||||
Common.Server.JSONSettings
|
Common.Server.JSONSettings
|
||||||
Common.Server.ConsumerSettings
|
Common.Server.ConsumerSettings
|
||||||
|
|
||||||
|
|
|
@ -13,5 +13,5 @@
|
||||||
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2hhbl9hcmNoaXZlciJ9.rGIKZokTDKTuQLIv8138bUby5PELfDipYYIDpJzH02c",
|
"jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiY2hhbl9hcmNoaXZlciJ9.rGIKZokTDKTuQLIv8138bUby5PELfDipYYIDpJzH02c",
|
||||||
"media_root_path": "/home/phil/linixy/tmp/chan_archive_media_repaired/archive",
|
"media_root_path": "/home/phil/linixy/tmp/chan_archive_media_repaired/archive",
|
||||||
"http_fill_all": false,
|
"http_fill_all": false,
|
||||||
"http_sync_continously": false
|
"http_sync_continously": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,6 +290,7 @@ SELECT DISTINCT ON (b.board_id)
|
||||||
JOIN posts p ON p.thread_id = t.thread_id
|
JOIN posts p ON p.thread_id = t.thread_id
|
||||||
ORDER BY b.board_id, p.creation_time DESC;
|
ORDER BY b.board_id, p.creation_time DESC;
|
||||||
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION get_latest_posts_per_board()
|
CREATE OR REPLACE FUNCTION get_latest_posts_per_board()
|
||||||
RETURNS TABLE (
|
RETURNS TABLE (
|
||||||
board_id int,
|
board_id int,
|
||||||
|
@ -298,7 +299,6 @@ RETURNS TABLE (
|
||||||
post_id bigint,
|
post_id bigint,
|
||||||
board_post_id bigint,
|
board_post_id bigint,
|
||||||
creation_time timestamp with time zone,
|
creation_time timestamp with time zone,
|
||||||
body text,
|
|
||||||
thread_id bigint,
|
thread_id bigint,
|
||||||
board_thread_id bigint
|
board_thread_id bigint
|
||||||
) AS $$
|
) AS $$
|
||||||
|
@ -309,7 +309,6 @@ RETURNS TABLE (
|
||||||
p.post_id,
|
p.post_id,
|
||||||
p.board_post_id,
|
p.board_post_id,
|
||||||
p.creation_time,
|
p.creation_time,
|
||||||
p.body,
|
|
||||||
t.thread_id,
|
t.thread_id,
|
||||||
t.board_thread_id
|
t.board_thread_id
|
||||||
FROM boards b
|
FROM boards b
|
||||||
|
|
|
@ -409,7 +409,6 @@ RETURNS TABLE (
|
||||||
post_id bigint,
|
post_id bigint,
|
||||||
board_post_id bigint,
|
board_post_id bigint,
|
||||||
creation_time timestamp with time zone,
|
creation_time timestamp with time zone,
|
||||||
body text,
|
|
||||||
thread_id bigint,
|
thread_id bigint,
|
||||||
board_thread_id bigint
|
board_thread_id bigint
|
||||||
) AS $$
|
) AS $$
|
||||||
|
@ -420,7 +419,6 @@ RETURNS TABLE (
|
||||||
p.post_id,
|
p.post_id,
|
||||||
p.board_post_id,
|
p.board_post_id,
|
||||||
p.creation_time,
|
p.creation_time,
|
||||||
p.body,
|
|
||||||
t.thread_id,
|
t.thread_id,
|
||||||
t.board_thread_id
|
t.board_thread_id
|
||||||
FROM boards b
|
FROM boards b
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE DeriveAnyClass #-}
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
||||||
|
{-# HLINT ignore "Use <&>" #-}
|
||||||
|
|
||||||
module Network.DataClient
|
module Network.DataClient
|
||||||
( HttpError(..)
|
( HttpError(..)
|
||||||
|
@ -19,6 +21,7 @@ module Network.DataClient
|
||||||
, postAttachments
|
, postAttachments
|
||||||
, getJSON
|
, getJSON
|
||||||
, getFile
|
, getFile
|
||||||
|
, getLatestPostsPerBoard
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad (forM)
|
import Control.Monad (forM)
|
||||||
|
@ -49,6 +52,7 @@ import qualified Common.AttachmentType as Attachments
|
||||||
import qualified Common.PostsType as Posts
|
import qualified Common.PostsType as Posts
|
||||||
import Common.Network.HttpClient
|
import Common.Network.HttpClient
|
||||||
import qualified Network.DataClientTypes as T
|
import qualified Network.DataClientTypes as T
|
||||||
|
import qualified Network.GetLatestPostsPerBoardResponse as GLPPBR
|
||||||
|
|
||||||
|
|
||||||
data PostId = PostId
|
data PostId = PostId
|
||||||
|
@ -233,14 +237,20 @@ getFile url = do
|
||||||
case result of
|
case result of
|
||||||
Left (err :: HttpError) -> do
|
Left (err :: HttpError) -> do
|
||||||
putStrLn $ "getFile " ++ url ++ " Error!"
|
putStrLn $ "getFile " ++ url ++ " Error!"
|
||||||
putStrLn $ show err
|
print err
|
||||||
return Nothing
|
return Nothing
|
||||||
Right lbs -> do
|
Right lbs -> do
|
||||||
putStrLn $ "getFile " ++ url ++ " SUCCESS!"
|
putStrLn $ "getFile " ++ url ++ " SUCCESS!"
|
||||||
tmp_root <- getCanonicalTemporaryDirectory
|
tmp_root <- getCanonicalTemporaryDirectory
|
||||||
(tmp_filepath, tmp_filehandle) <- openBinaryTempFile tmp_root "chan.attachment"
|
(tmp_filepath, tmp_filehandle) <- openBinaryTempFile tmp_root "chan.attachment"
|
||||||
putStrLn $ "Created " ++ tmp_filepath
|
putStrLn $ "Created " ++ tmp_filepath
|
||||||
putStrLn $ "Writing attachment..."
|
putStrLn "Writing attachment..."
|
||||||
LBS.hPut tmp_filehandle lbs
|
LBS.hPut tmp_filehandle lbs
|
||||||
hClose tmp_filehandle
|
hClose tmp_filehandle
|
||||||
return $ Just tmp_filepath
|
return $ Just tmp_filepath
|
||||||
|
|
||||||
|
|
||||||
|
-- | Function to handle each chunk.
|
||||||
|
getLatestPostsPerBoard :: T.JSONSettings -> IO (Either HttpError [ GLPPBR.GetLatestPostsPerBoardResponse ])
|
||||||
|
getLatestPostsPerBoard settings =
|
||||||
|
post settings "/rpc/get_latest_posts_per_board" mempty False >>= return . eitherDecodeResponse
|
||||||
|
|
|
@ -10,4 +10,3 @@ data ThreadMaxIdx = ThreadMaxIdx
|
||||||
{ thread_id :: Int64
|
{ thread_id :: Int64
|
||||||
, max_idx :: Int
|
, max_idx :: Int
|
||||||
} deriving (Show, Generic, FromJSON)
|
} deriving (Show, Generic, FromJSON)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
|
|
||||||
|
module Network.GetLatestPostsPerBoardResponse
|
||||||
|
where
|
||||||
|
|
||||||
|
import Data.Int (Int64)
|
||||||
|
import Data.Time.Clock (UTCTime)
|
||||||
|
import Data.Aeson (FromJSON)
|
||||||
|
import GHC.Generics
|
||||||
|
|
||||||
|
data GetLatestPostsPerBoardResponse = GetLatestPostsPerBoardResponse
|
||||||
|
{ board_id :: Int
|
||||||
|
, site_id :: Int
|
||||||
|
, pathpart :: String
|
||||||
|
, post_id :: Maybe Int64
|
||||||
|
, board_post_id :: Int64
|
||||||
|
, creation_time :: UTCTime
|
||||||
|
, thread_id :: Int64
|
||||||
|
, board_thread_id :: Integer
|
||||||
|
} deriving (Show, Generic, FromJSON)
|
32
src/Sync.hs
32
src/Sync.hs
|
@ -1,21 +1,31 @@
|
||||||
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
|
||||||
module Sync where
|
module Sync where
|
||||||
|
|
||||||
import Common.Server.ConsumerSettings
|
import Common.Server.ConsumerSettings as Settings
|
||||||
import Lib (getBoards, toClientSettings)
|
import Common.Server.JSONSettings as JSONSettings
|
||||||
import SitesType (Site)
|
import Network.DataClient (getLatestPostsPerBoard)
|
||||||
import BoardsType (Board)
|
|
||||||
|
|
||||||
getSiteBoards :: ConsumerJSONSettings -> JSONSiteSettings -> IO (Site, [ Board ])
|
consumerSettingsToPartialJSONSettings :: Settings.ConsumerJSONSettings -> JSONSettings.JSONSettings
|
||||||
getSiteBoards settings site_settings =
|
consumerSettingsToPartialJSONSettings ConsumerJSONSettings {..} =
|
||||||
let client_settings = toClientSettings settings site_settings
|
JSONSettings
|
||||||
in getBoards
|
{ JSONSettings.postgrest_url = postgrest_url
|
||||||
client_settings
|
, JSONSettings.jwt = jwt
|
||||||
(boards site_settings)
|
, backup_read_root = undefined
|
||||||
|
, JSONSettings.media_root_path
|
||||||
|
, site_name = undefined
|
||||||
|
, site_url = undefined
|
||||||
|
}
|
||||||
|
|
||||||
syncWebsites :: ConsumerJSONSettings -> IO ()
|
syncWebsites :: ConsumerJSONSettings -> IO ()
|
||||||
syncWebsites _ = do
|
syncWebsites consumer_settings = do
|
||||||
putStrLn "Starting channel web synchronization."
|
putStrLn "Starting channel web synchronization."
|
||||||
|
|
||||||
|
let json_settings = consumerSettingsToPartialJSONSettings consumer_settings
|
||||||
|
|
||||||
|
asdf <- getLatestPostsPerBoard json_settings
|
||||||
|
|
||||||
|
print asdf
|
||||||
-- first we need all the (Site, Board) tuples
|
-- first we need all the (Site, Board) tuples
|
||||||
-- perhaps we even want all (Site, Board, Thread) pairs
|
-- perhaps we even want all (Site, Board, Thread) pairs
|
||||||
-- But then we don't load the posts of each thread, instead only do
|
-- But then we don't load the posts of each thread, instead only do
|
||||||
|
|
Loading…
Reference in New Issue