Compare commits
No commits in common. "e290dac0c3c74c05e8911351e2d7179e1dbcf262" and "9e3c054c53bb0ca66da67cc2537eb68a52bbcaf3" have entirely different histories.
e290dac0c3
...
9e3c054c53
|
@ -72,7 +72,7 @@ CREATE TABLE IF NOT EXISTS posts
|
||||||
, email text
|
, email text
|
||||||
, body_search_index tsvector
|
, body_search_index tsvector
|
||||||
, thread_id bigint NOT NULL
|
, thread_id bigint NOT NULL
|
||||||
, embed text
|
-- , TODO: embed
|
||||||
, CONSTRAINT unique_thread_board_id_constraint UNIQUE (thread_id, board_post_id)
|
, CONSTRAINT unique_thread_board_id_constraint UNIQUE (thread_id, board_post_id)
|
||||||
, CONSTRAINT thread_fk FOREIGN KEY (thread_id) REFERENCES threads (thread_id) ON DELETE CASCADE
|
, CONSTRAINT thread_fk FOREIGN KEY (thread_id) REFERENCES threads (thread_id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
@ -225,7 +225,6 @@ RETURNS TABLE (
|
||||||
body text,
|
body text,
|
||||||
subject text,
|
subject text,
|
||||||
thread_id bigint,
|
thread_id bigint,
|
||||||
embed text,
|
|
||||||
board_thread_id bigint,
|
board_thread_id bigint,
|
||||||
pathpart text,
|
pathpart text,
|
||||||
site_name text,
|
site_name text,
|
||||||
|
@ -251,8 +250,7 @@ RETURNS TABLE (
|
||||||
top.bump_time,
|
top.bump_time,
|
||||||
posts.body,
|
posts.body,
|
||||||
posts.subject,
|
posts.subject,
|
||||||
posts.thread_id,
|
posts.thread_id
|
||||||
posts.embed
|
|
||||||
FROM top
|
FROM top
|
||||||
JOIN posts ON top.thread_id = posts.thread_id
|
JOIN posts ON top.thread_id = posts.thread_id
|
||||||
WHERE creation_time < max_time
|
WHERE creation_time < max_time
|
||||||
|
|
|
@ -13,7 +13,6 @@ RETURNS TABLE (
|
||||||
body text,
|
body text,
|
||||||
subject text,
|
subject text,
|
||||||
thread_id bigint,
|
thread_id bigint,
|
||||||
embed text,
|
|
||||||
board_thread_id bigint,
|
board_thread_id bigint,
|
||||||
pathpart text,
|
pathpart text,
|
||||||
site_name text,
|
site_name text,
|
||||||
|
@ -39,8 +38,7 @@ RETURNS TABLE (
|
||||||
top.bump_time,
|
top.bump_time,
|
||||||
posts.body,
|
posts.body,
|
||||||
posts.subject,
|
posts.subject,
|
||||||
posts.thread_id,
|
posts.thread_id
|
||||||
posts.embed
|
|
||||||
FROM top
|
FROM top
|
||||||
JOIN posts ON top.thread_id = posts.thread_id
|
JOIN posts ON top.thread_id = posts.thread_id
|
||||||
WHERE creation_time < max_time
|
WHERE creation_time < max_time
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
REVOKE EXECUTE ON FUNCTION insert_posts_and_return_ids FROM PUBLIC;
|
|
||||||
DROP FUNCTION IF EXISTS insert_posts_and_return_ids(new_posts posts[]);
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION insert_posts_and_return_ids(new_posts posts[])
|
|
||||||
RETURNS TABLE (post_id bigint, board_post_id bigint, thread_id bigint) AS $$
|
|
||||||
WITH
|
|
||||||
selected AS (
|
|
||||||
SELECT post_id, board_post_id, thread_id, embed
|
|
||||||
FROM posts
|
|
||||||
WHERE (thread_id, board_post_id) IN (SELECT thread_id, board_post_id FROM unnest(new_posts))
|
|
||||||
),
|
|
||||||
to_update AS (
|
|
||||||
SELECT s.post_id, np.embed
|
|
||||||
FROM unnest(new_posts) AS np
|
|
||||||
JOIN selected s ON np.thread_id = s.thread_id AND np.board_post_id = s.board_post_id
|
|
||||||
WHERE s.embed IS DISTINCT FROM np.embed
|
|
||||||
),
|
|
||||||
updated AS (
|
|
||||||
UPDATE posts p
|
|
||||||
SET embed = tu.embed
|
|
||||||
FROM to_update tu
|
|
||||||
WHERE p.post_id = tu.post_id
|
|
||||||
RETURNING p.post_id, p.board_post_id, p.thread_id, p.embed
|
|
||||||
),
|
|
||||||
to_insert AS (
|
|
||||||
SELECT np.*
|
|
||||||
FROM unnest(new_posts) AS np
|
|
||||||
LEFT OUTER JOIN selected s ON np.thread_id = s.thread_id AND np.board_post_id = s.board_post_id
|
|
||||||
WHERE s.post_id IS NULL
|
|
||||||
),
|
|
||||||
inserted AS (
|
|
||||||
INSERT INTO posts (board_post_id, creation_time, body, subject, name, email, thread_id, embed)
|
|
||||||
SELECT board_post_id, creation_time, body, subject, name, email, thread_id, embed
|
|
||||||
FROM to_insert
|
|
||||||
RETURNING post_id, board_post_id, thread_id, embed
|
|
||||||
)
|
|
||||||
SELECT post_id, board_post_id, thread_id FROM inserted
|
|
||||||
UNION ALL
|
|
||||||
SELECT post_id, board_post_id, thread_id FROM updated
|
|
||||||
UNION ALL
|
|
||||||
SELECT post_id, board_post_id, thread_id FROM selected WHERE post_id NOT IN (SELECT post_id FROM updated);
|
|
||||||
$$ LANGUAGE sql;
|
|
||||||
|
|
||||||
GRANT EXECUTE ON FUNCTION insert_posts_and_return_ids TO chan_archiver;
|
|
|
@ -212,7 +212,6 @@ apiPostToArchivePost thread post =
|
||||||
, Posts.subject = JSONPosts.sub post
|
, Posts.subject = JSONPosts.sub post
|
||||||
, Posts.email = JSONPosts.email post
|
, Posts.email = JSONPosts.email post
|
||||||
, Posts.thread_id = Threads.thread_id thread
|
, Posts.thread_id = Threads.thread_id thread
|
||||||
, Posts.embed = JSONPosts.embed post
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | A version of 'concatMap' that works with a monadic predicate.
|
-- | A version of 'concatMap' that works with a monadic predicate.
|
||||||
|
@ -587,10 +586,7 @@ processBackupDirectory settings = do
|
||||||
-- - it's saged by a mod
|
-- - it's saged by a mod
|
||||||
-- - the post has sage in the email field
|
-- - the post has sage in the email field
|
||||||
-- - the thread is full.
|
-- - the thread is full.
|
||||||
--
|
|
||||||
-- Better to support all those flags via the api: saged, locked, cyclical?, sticky
|
|
||||||
-- - deleted could be there too
|
|
||||||
-- - edited could be there too
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a5ad7272548d0096ef7aca3ac354d69616adbdd4
|
Subproject commit 3f420d3131eb0477b522103a582732a5ba365f19
|
|
@ -25,7 +25,6 @@ import Network.HTTP.Client
|
||||||
( newManager
|
( newManager
|
||||||
, managerSetMaxHeaderLength
|
, managerSetMaxHeaderLength
|
||||||
, httpLbs
|
, httpLbs
|
||||||
, responseTimeoutNone
|
|
||||||
)
|
)
|
||||||
import qualified Data.ByteString.Lazy.Char8 as BL
|
import qualified Data.ByteString.Lazy.Char8 as BL
|
||||||
import Network.HTTP.Client.Conduit (defaultManagerSettings)
|
import Network.HTTP.Client.Conduit (defaultManagerSettings)
|
||||||
|
@ -91,9 +90,8 @@ post
|
||||||
-> IO (Either HttpError LBS.ByteString)
|
-> IO (Either HttpError LBS.ByteString)
|
||||||
post settings path payload return_repr = do
|
post settings path payload return_repr = do
|
||||||
let requestUrl = T.postgrest_url settings ++ path
|
let requestUrl = T.postgrest_url settings ++ path
|
||||||
req <- parseRequest requestUrl
|
initReq <- parseRequest requestUrl
|
||||||
let initReq = setRequestResponseTimeout responseTimeoutNone req
|
let req = setRequestMethod "POST"
|
||||||
let request = setRequestMethod "POST"
|
|
||||||
. setRequestHeader "Authorization" [ jwt_header ]
|
. setRequestHeader "Authorization" [ jwt_header ]
|
||||||
. setRequestHeader "Content-Type" [ "application/json" ]
|
. setRequestHeader "Content-Type" [ "application/json" ]
|
||||||
. setRequestBodyLBS payload
|
. setRequestBodyLBS payload
|
||||||
|
@ -102,7 +100,7 @@ post settings path payload return_repr = do
|
||||||
|
|
||||||
putStrLn $ "posting to " ++ requestUrl
|
putStrLn $ "posting to " ++ requestUrl
|
||||||
-- putStrLn $ "Payload: " ++ (LC8.unpack payload)
|
-- putStrLn $ "Payload: " ++ (LC8.unpack payload)
|
||||||
handleHttp (httpLBS request)
|
handleHttp (httpLBS req)
|
||||||
|
|
||||||
where
|
where
|
||||||
jwt_header = C8.pack $ "Bearer " ++ T.jwt settings
|
jwt_header = C8.pack $ "Bearer " ++ T.jwt settings
|
||||||
|
|
|
@ -22,7 +22,6 @@ data Post = Post
|
||||||
, locked :: Maybe Int
|
, locked :: Maybe Int
|
||||||
, cyclical :: Maybe J.Cyclical
|
, cyclical :: Maybe J.Cyclical
|
||||||
, last_modified :: Int
|
, last_modified :: Int
|
||||||
, embed :: Maybe Text
|
|
||||||
, board :: Text
|
, board :: Text
|
||||||
, files :: Maybe [J.File]
|
, files :: Maybe [J.File]
|
||||||
, resto :: Int
|
, resto :: Int
|
||||||
|
|
Loading…
Reference in New Issue