We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 1447aa6d authored by Mitchell Rosen's avatar Mitchell Rosen

switch to SharesPledged from Pledge for feed info (to capture history)

parent 9fec3c83
......@@ -389,14 +389,14 @@ messageEventHandler _ = return ()
-- | Handler in charge of inserting events (stripped down) into a separate table for each type.
eventInserterHandler :: SnowdriftEvent -> Daemon ()
-- If an unapproved comment is sent as an ECommentPosted event, bad things will happen (fromJust).
eventInserterHandler (ECommentPosted comment_id Comment{..}) = runDB (insert_ (EventCommentPosted (fromJust commentModeratedTs) comment_id))
eventInserterHandler (ECommentPending comment_id Comment{..}) = runDB (insert_ (EventCommentPending commentCreatedTs comment_id))
eventInserterHandler (EMessageSent message_id Message{..}) = runDB (insert_ (EventMessageSent messageCreatedTs message_id))
eventInserterHandler (EWikiPage wiki_page_id WikiPage{..}) = runDB (insert_ (EventWikiPage wikiPageCreatedTs wiki_page_id))
eventInserterHandler (EWikiEdit wiki_edit_id WikiEdit{..}) = runDB (insert_ (EventWikiEdit wikiEditTs wiki_edit_id))
eventInserterHandler (ENewPledge pledge_id Pledge{..}) = runDB (insert_ (EventNewPledge pledgeCreatedTs pledge_id))
eventInserterHandler (EUpdatedPledge old_shares pledge_id Pledge{..}) = runDB (insert_ (EventUpdatedPledge pledgeCreatedTs old_shares pledge_id))
eventInserterHandler (EDeletedPledge ts user_id project_id shares) = runDB (insert_ (EventDeletedPledge ts user_id project_id shares))
eventInserterHandler (ECommentPosted comment_id Comment{..}) = runDB (insert_ (EventCommentPosted (fromJust commentModeratedTs) comment_id))
eventInserterHandler (ECommentPending comment_id Comment{..}) = runDB (insert_ (EventCommentPending commentCreatedTs comment_id))
eventInserterHandler (EMessageSent message_id Message{..}) = runDB (insert_ (EventMessageSent messageCreatedTs message_id))
eventInserterHandler (EWikiPage wiki_page_id WikiPage{..}) = runDB (insert_ (EventWikiPage wikiPageCreatedTs wiki_page_id))
eventInserterHandler (EWikiEdit wiki_edit_id WikiEdit{..}) = runDB (insert_ (EventWikiEdit wikiEditTs wiki_edit_id))
eventInserterHandler (ENewPledge shares_pledged_id SharesPledged{..}) = runDB (insert_ (EventNewPledge sharesPledgedTs shares_pledged_id))
eventInserterHandler (EUpdatedPledge old_shares shares_pledged_id SharesPledged{..}) = runDB (insert_ (EventUpdatedPledge sharesPledgedTs old_shares shares_pledged_id))
eventInserterHandler (EDeletedPledge ts user_id project_id shares) = runDB (insert_ (EventDeletedPledge ts user_id project_id shares))
renderRoute' :: Route App -> App -> Text
renderRoute' route app =
......
......@@ -449,9 +449,9 @@ getProjectFeedR project_handle = do
-- data to display the project feed row, it MUST be used to fetch the data below!
-- The Maybes from Data.Map.lookup are unsafely STRIPPED in the views!
let comments = map entityVal (comment_posted_entities <> comment_pending_entities)
wiki_edits = map entityVal wiki_edit_entities
pledges = map entityVal (new_pledge_entities <> (map snd updated_pledges))
let comments = map entityVal (comment_posted_entities <> comment_pending_entities)
wiki_edits = map entityVal wiki_edit_entities
shares_pledged = map entityVal (new_pledge_entities <> (map snd updated_pledges))
-- WikiPages that can be keyed by a Comment's DiscussionId (i.e. the Comment *is* on a WikiPage)
discussion_wiki_pages_map <- M.fromList . map (\e@(Entity _ WikiPage{..}) -> (wikiPageDiscussion, e)) <$>
......@@ -465,7 +465,7 @@ getProjectFeedR project_handle = do
users_map <- (\a b c d -> a <> b <> c <> d)
<$> (entitiesMap <$> fetchUsersInDB (map commentUser comments))
<*> (entitiesMap <$> fetchUsersInDB (map wikiEditUser wiki_edits))
<*> (entitiesMap <$> fetchUsersInDB (map pledgeUser pledges))
<*> (entitiesMap <$> fetchUsersInDB (map sharesPledgedUser shares_pledged))
<*> (entitiesMap <$> fetchUsersInDB (map (\(EventDeletedPledge _ user_id _ _) -> user_id) deleted_pledge_events))
let events = sortBy snowdriftEventNewestToOldest . mconcat $
......@@ -481,8 +481,8 @@ getProjectFeedR project_handle = do
defaultLayout $(widgetFile "project_feed")
where
-- "event updated pledge to snowdrift event". Makes above code cleaner.
eup2se :: (Int64, Entity Pledge) -> SnowdriftEvent
eup2se (old_shares, Entity pledge_id pledge) = EUpdatedPledge old_shares pledge_id pledge
eup2se :: (Int64, Entity SharesPledged) -> SnowdriftEvent
eup2se (old_shares, Entity shares_pledged_id shares_pledged) = EUpdatedPledge old_shares shares_pledged_id shares_pledged
-- "event deleted pledge to snowdrift event". Makes above code cleaner.
edp2se :: EventDeletedPledge -> SnowdriftEvent
......
......@@ -59,10 +59,13 @@ insertProjectPledgeDB :: UserId
-> SDB ()
insertProjectPledgeDB user_id project_id shares pledge_render_id = do
now <- liftIO getCurrentTime
lift $ insert_ (SharesPledged now user_id shares pledge_render_id)
let pledge = Pledge now user_id project_id shares shares
insertBy pledge >>= \case
Left (Entity pledge_id _) -> do
let shares_pledged = SharesPledged now user_id project_id shares pledge_render_id
shares_pledged_id <- lift (insert shares_pledged)
getBy (UniquePledge user_id project_id) >>= \case
Nothing -> do
pledge_id <- lift $ insert_ (Pledge now user_id project_id shares shares)
tell [ENewPledge shares_pledged_id shares_pledged]
Just (Entity pledge_id old_pledge) -> do
if shares == 0
then do
lift (deleteKey pledge_id)
......@@ -74,8 +77,7 @@ insertProjectPledgeDB user_id project_id shares pledge_render_id = do
, PledgeFundedShares =. val shares
]
where_ (p ^. PledgeId ==. val pledge_id)
tell [EUpdatedPledge shares pledge_id pledge]
Right pledge_id -> tell [ENewPledge pledge_id pledge]
tell [EUpdatedPledge (pledgeShares old_pledge) shares_pledged_id shares_pledged]
getGithubIssues :: Project -> Handler [GH.Issue]
getGithubIssues project =
......@@ -236,27 +238,27 @@ fetchProjectWikiEditsBeforeDB project_id before =
exprWikiPageOnProject wp project_id
return we
-- | Fetch all new Pledges made on this Project before this time.
fetchProjectNewPledgesBeforeDB :: ProjectId -> UTCTime -> DB [Entity Pledge]
-- | Fetch all new SharesPledged made on this Project before this time.
fetchProjectNewPledgesBeforeDB :: ProjectId -> UTCTime -> DB [Entity SharesPledged]
fetchProjectNewPledgesBeforeDB project_id before =
select $
from $ \(enp `InnerJoin` p) -> do
on_ (enp ^. EventNewPledgePledge ==. p ^. PledgeId)
from $ \(enp `InnerJoin` sp) -> do
on_ (enp ^. EventNewPledgeSharesPledged ==. sp ^. SharesPledgedId)
where_ $
enp ^. EventNewPledgeTs <=. val before &&.
p ^. PledgeProject ==. val project_id
return p
sp ^. SharesPledgedProject ==. val project_id
return sp
-- | Fetch all updated Pledges made on this Project before this time, along with the old number of shares.
fetchProjectUpdatedPledgesBeforeDB :: ProjectId -> UTCTime -> DB [(Int64, Entity Pledge)]
fetchProjectUpdatedPledgesBeforeDB :: ProjectId -> UTCTime -> DB [(Int64, Entity SharesPledged)]
fetchProjectUpdatedPledgesBeforeDB project_id before = fmap (map (\(Value n, p) -> (n, p))) $
select $
from $ \(eup `InnerJoin` p) -> do
on_ (eup ^. EventUpdatedPledgePledge ==. p ^. PledgeId)
from $ \(eup `InnerJoin` sp) -> do
on_ (eup ^. EventUpdatedPledgeSharesPledged ==. sp ^. SharesPledgedId)
where_ $
eup ^. EventUpdatedPledgeTs <=. val before &&.
p ^. PledgeProject ==. val project_id
return (eup ^. EventUpdatedPledgeOldShares, p)
sp ^. SharesPledgedProject ==. val project_id
return (eup ^. EventUpdatedPledgeOldShares, sp)
-- | Fetch all deleted pledge events made on this Project before this time.
fetchProjectDeletedPledgesBeforeDB :: ProjectId -> UTCTime -> DB [EventDeletedPledge]
......
......@@ -8,11 +8,11 @@ snowdriftEventNewestToOldest :: SnowdriftEvent -> SnowdriftEvent -> Ordering
snowdriftEventNewestToOldest x y = compare (snowdriftEventTime y) (snowdriftEventTime x)
snowdriftEventTime :: SnowdriftEvent -> UTCTime
snowdriftEventTime (ECommentPosted _ Comment{..}) = fromMaybe commentCreatedTs commentModeratedTs
snowdriftEventTime (ECommentPending _ Comment{..}) = commentCreatedTs
snowdriftEventTime (EMessageSent _ Message{..}) = messageCreatedTs
snowdriftEventTime (EWikiEdit _ WikiEdit{..}) = wikiEditTs
snowdriftEventTime (EWikiPage _ WikiPage{..}) = wikiPageCreatedTs
snowdriftEventTime (ENewPledge _ Pledge{..}) = pledgeCreatedTs
snowdriftEventTime (EUpdatedPledge _ _ Pledge{..}) = pledgeCreatedTs
snowdriftEventTime (EDeletedPledge ts _ _ _) = ts
snowdriftEventTime (ECommentPosted _ Comment{..}) = fromMaybe commentCreatedTs commentModeratedTs
snowdriftEventTime (ECommentPending _ Comment{..}) = commentCreatedTs
snowdriftEventTime (EMessageSent _ Message{..}) = messageCreatedTs
snowdriftEventTime (EWikiEdit _ WikiEdit{..}) = wikiEditTs
snowdriftEventTime (EWikiPage _ WikiPage{..}) = wikiPageCreatedTs
snowdriftEventTime (ENewPledge _ SharesPledged{..}) = sharesPledgedTs
snowdriftEventTime (EUpdatedPledge _ _ SharesPledged{..}) = sharesPledgedTs
snowdriftEventTime (EDeletedPledge ts _ _ _) = ts
......@@ -19,9 +19,9 @@ data SnowdriftEvent
-- New WikiPage posted.
| EWikiPage WikiPageId WikiPage
-- New pledge.
| ENewPledge PledgeId Pledge
| ENewPledge SharesPledgedId SharesPledged
-- Pledge that has changed in value.
| EUpdatedPledge Int64 {- old shares -}
PledgeId Pledge {- new pledge info -}
SharesPledgedId SharesPledged {- new pledge info -}
-- Deleted pledge.
| EDeletedPledge UTCTime UserId ProjectId Int64
......@@ -42,19 +42,19 @@ renderWikiEditEvent _ _ (Entity _ wiki_page) =
<div>#{wikiPageTarget wiki_page} edit!
|]
renderNewPledgeEvent :: PledgeId -> Pledge -> UserMap -> Widget
renderNewPledgeEvent pledge_id Pledge{..} users_map = do
let pledger = users_map ! pledgeUser
renderNewPledgeEvent :: SharesPledgedId -> SharesPledged -> UserMap -> Widget
renderNewPledgeEvent shares_pledged_id SharesPledged{..} users_map = do
let pledger = users_map ! sharesPledgedUser
[whamlet|
<div>#{userPrintName (Entity pledgeUser pledger)} pledged #{show pledgeShares} new shares!
<div>#{userPrintName (Entity sharesPledgedUser pledger)} pledged #{show sharesPledgedShares} new shares!
|]
renderUpdatedPledgeEvent :: Int64 -> PledgeId -> Pledge -> UserMap -> Widget
renderUpdatedPledgeEvent old_shares pledge_id Pledge{..} users_map = do
let pledger = users_map ! pledgeUser
direction_text = if old_shares < pledgeShares then "down " else "up " :: Text
renderUpdatedPledgeEvent :: Int64 -> SharesPledgedId -> SharesPledged -> UserMap -> Widget
renderUpdatedPledgeEvent old_shares shares_pledged_id SharesPledged{..} users_map = do
let pledger = users_map ! sharesPledgedUser
direction_text = if old_shares < sharesPledgedShares then "down " else "up " :: Text
[whamlet|
<div>#{userPrintName (Entity pledgeUser pledger)} pledged #{show pledgeShares} shares! (#{direction_text} from #{show old_shares})
<div>#{userPrintName (Entity sharesPledgedUser pledger)} pledged #{show sharesPledgedShares} shares! (#{direction_text} from #{show old_shares})
|]
renderDeletedPledgeEvent :: UserId -> Int64 -> UserMap -> Widget
......
......@@ -345,6 +345,7 @@ PledgeFormRendered
SharesPledged
ts UTCTime
user UserId
project ProjectId
shares Int64
render PledgeFormRenderedId
......@@ -379,12 +380,12 @@ EventWikiEdit
EventNewPledge
ts UTCTime
pledge PledgeId
sharesPledged SharesPledgedId
EventUpdatedPledge
ts UTCTime
oldShares Int64
pledge PledgeId
sharesPledged SharesPledgedId
EventDeletedPledge
ts UTCTime
......
ALTER TABLE "pledge" ADD COLUMN "created_ts" TIMESTAMP NOT NULL DEFAULT now();
ALTER TABLE "wiki_page" ADD COLUMN "created_ts" TIMESTAMP NOT NULL DEFAULT now();
CREATe TABLE "event_wiki_page"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"wiki_page" INT8 NOT NULL);
ALTER TABLE "event_wiki_page" ADD CONSTRAINT "event_wiki_page_wiki_page_fkey" FOREIGN KEY("wiki_page") REFERENCES "wiki_page"("id");
CREATe TABLE "event_new_pledge"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"pledge" INT8 NOT NULL);
ALTER TABLE "event_new_pledge" ADD CONSTRAINT "event_new_pledge_pledge_fkey" FOREIGN KEY("pledge") REFERENCES "pledge"("id");
CREATe TABLE "event_updated_pledge"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"old_shares" INT8 NOT NULL,"pledge" INT8 NOT NULL);
ALTER TABLE "event_updated_pledge" ADD CONSTRAINT "event_updated_pledge_pledge_fkey" FOREIGN KEY("pledge") REFERENCES "pledge"("id");
CREATe TABLE "event_deleted_pledge"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"user" INT8 NOT NULL,"project" INT8 NOT NULL,"shares" INT8 NOT NULL);
ALTER TABLE "event_deleted_pledge" ADD CONSTRAINT "event_deleted_pledge_user_fkey" FOREIGN KEY("user") REFERENCES "user"("id");
ALTER TABLE "event_deleted_pledge" ADD CONSTRAINT "event_deleted_pledge_project_fkey" FOREIGN KEY("project") REFERENCES "project"("id");
DROP TABLE "shares_pledged" CASCADE;
ALTER TABLE "pledge" ADD COLUMN "created_ts" TIMESTAMP NOT NULL DEFAULT now();
ALTER TABLE "wiki_page" ADD COLUMN "created_ts" TIMESTAMP NOT NULL DEFAULT now();
CREATe TABLE "shares_pledged"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"user" INT8 NOT NULL,"project" INT8 NOT NULL,"shares" INT8 NOT NULL,"render" INT8 NOT NULL);
ALTER TABLE "shares_pledged" ADD CONSTRAINT "shares_pledged_user_fkey" FOREIGN KEY("user") REFERENCES "user"("id");
ALTER TABLE "shares_pledged" ADD CONSTRAINT "shares_pledged_project_fkey" FOREIGN KEY("project") REFERENCES "project"("id");
ALTER TABLE "shares_pledged" ADD CONSTRAINT "shares_pledged_render_fkey" FOREIGN KEY("render") REFERENCES "pledge_form_rendered"("id");
CREATe TABLE "event_wiki_page"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"wiki_page" INT8 NOT NULL);
ALTER TABLE "event_wiki_page" ADD CONSTRAINT "event_wiki_page_wiki_page_fkey" FOREIGN KEY("wiki_page") REFERENCES "wiki_page"("id");
CREATe TABLE "event_new_pledge"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"shares_pledged" INT8 NOT NULL);
ALTER TABLE "event_new_pledge" ADD CONSTRAINT "event_new_pledge_shares_pledged_fkey" FOREIGN KEY("shares_pledged") REFERENCES "shares_pledged"("id");
CREATe TABLE "event_updated_pledge"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"old_shares" INT8 NOT NULL,"shares_pledged" INT8 NOT NULL);
ALTER TABLE "event_updated_pledge" ADD CONSTRAINT "event_updated_pledge_shares_pledged_fkey" FOREIGN KEY("shares_pledged") REFERENCES "shares_pledged"("id");
CREATe TABLE "event_deleted_pledge"("id" SERIAL PRIMARY KEY UNIQUE,"ts" TIMESTAMP NOT NULL,"user" INT8 NOT NULL,"project" INT8 NOT NULL,"shares" INT8 NOT NULL);
ALTER TABLE "event_deleted_pledge" ADD CONSTRAINT "event_deleted_pledge_user_fkey" FOREIGN KEY("user") REFERENCES "user"("id");
ALTER TABLE "event_deleted_pledge" ADD CONSTRAINT "event_deleted_pledge_project_fkey" FOREIGN KEY("project") REFERENCES "project"("id");
......@@ -30,11 +30,11 @@ $forall event <- events
$of EWikiEdit wiki_edit_id wiki_edit
^{renderWikiEditEvent wiki_edit_id wiki_edit (Entity (wikiEditPage wiki_edit) (fromJust $ M.lookup (wikiEditPage wiki_edit) wiki_pages_map))}
$of ENewPledge pledge_id pledge
^{renderNewPledgeEvent pledge_id pledge users_map}
$of ENewPledge shares_pledged_id shares_pledged
^{renderNewPledgeEvent shares_pledged_id shares_pledged users_map}
$of EUpdatedPledge old_shares pledge_id pledge
^{renderUpdatedPledgeEvent old_shares pledge_id pledge users_map}
$of EUpdatedPledge old_shares shares_pledged_id shares_pledged
^{renderUpdatedPledgeEvent old_shares shares_pledged_id shares_pledged users_map}
$of EDeletedPledge _ user_id _ shares
^{renderDeletedPledgeEvent user_id shares users_map}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment