-
Notifications
You must be signed in to change notification settings - Fork 10
#389 jsonb #390
base: develop
Are you sure you want to change the base?
#389 jsonb #390
Conversation
back/benchmarks/Main.hs
Outdated
@@ -0,0 +1,49 @@ | |||
-- | Module contains all stuff to migrate from AcidState to Postgres. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong description?
back/benchmarks/Main.hs
Outdated
"Database" | ||
[ bench "select" $ nfIO $ | ||
runTransactionExceptT conn Read $ selectCategory "category1111" | ||
, bench "updete" $ nfIO $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
, bench "updete" $ nfIO $ | |
, bench "update" $ nfIO $ |
back/benchmarks/Main.hs
Outdated
bgroup | ||
"Database" | ||
[ bench "select" $ nfIO $ | ||
runTransactionExceptT conn Read $ selectCategory "category1111" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let's not have such names in code, they look sloppy. "category" or "uid1" would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
length "category1111" == 12 as Uid needed.
back/benchmarks/Main.hs
Outdated
|
||
main :: IO () | ||
main = do | ||
conn <- connect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two-space indentation.
back/benchmarks/Main.hs
Outdated
runTransactionExceptT conn Write $ updateCategory "category1111" update | ||
] | ||
update :: Category -> Category | ||
update = _categoryTitle .~ "title10" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the first application of update
the title will be "title10"
, so update
will be equivalent to id
and updateCategory
will not do any writes. You should do something that would change the category every time, e.g. _categoryTitle <>~ "+"
, and then re-run the benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -74,6 +76,20 @@ instance Aeson.ToJSON Trait where | |||
toJSON = Aeson.genericToJSON Aeson.defaultOptions { | |||
Aeson.fieldLabelModifier = over _head toLower . drop (T.length "trait") } | |||
|
|||
instance Aeson.FromJSON Trait where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this instance is not using generic
, the ToJSON
instance should also not use generic
.
back/src/Guide/Types/Core.hs
Outdated
instance Aeson.FromJSON Trait where | ||
parseJSON = Aeson.withObject "Trait" $ \o -> do | ||
traitUid <- o Aeson..: "uid" | ||
content <- o Aeson..: "content" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since MarkdownInline
has a FromJSON
instance, you can just write traitContent <- o Aeson..: "content"
.
back/src/Guide/Types/Core.hs
Outdated
traitContent <- toMarkdownInline <$> content Aeson..: "text" | ||
pure Trait{..} | ||
|
||
instance ToPostgres Trait where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this instance used anywhere?
back/src/Guide/Types/Core.hs
Outdated
pure Trait{..} | ||
|
||
instance ToPostgres Trait where | ||
toPostgres = toByteString . Aeson.encode >$< HE.jsonbBytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you using jsonbBytes
instead of just jsonb
? (Same for all other instances.)
back/src/Guide/Types/Core.hs
Outdated
itemCreated <- o Aeson..: "created" | ||
itemHackage <- o Aeson..:? "hackage" | ||
summary <- o Aeson..: "summary" | ||
itemSummary <- toMarkdownBlock <$> summary Aeson..: "text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, toMarkdownBlock
is not needed because MarkdownBlock already has a FromJSON instance.
ee90723
to
4f0c0a9
Compare
back/package.yaml
Outdated
- hasql-transaction | ||
|
||
ghc-options: | ||
- -O |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this won't have any effect if the library is not compiled with -O
, so you can just remove it and add a short instruction on how to run benchmarks properly to the README
.
back/src/Guide/Database/Import.hs
Outdated
import Guide.Config | ||
import Guide.Logger | ||
|
||
|
||
-- | Load categories and deleted categories from acid state to postgres | ||
-- | Load categories and archives categories from acid state to postgres |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- | Load categories and archives categories from acid state to postgres | |
-- | Load categories and archived categories from acid state to postgres |
Is this what you meant?
back/src/Guide/Database/Import.hs
Outdated
<- runTransactionExceptT conn Read getCategories | ||
catPostgres <- runTransactionExceptT conn Read $ | ||
selectCategories (#archived False) | ||
catarchivedPostgres <- runTransactionExceptT conn Read $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catarchivedPostgres <- runTransactionExceptT conn Read $ | |
catArchivedPostgres <- runTransactionExceptT conn Read $ |
back/src/Guide/Database/Import.hs
Outdated
let checkedCatDeleted = | ||
sortOn categoryUid catDeletedPostgres == | ||
sortOn categoryUid catarchivedPostgres == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sortOn categoryUid catarchivedPostgres == | |
sortOn categoryUid catArchivedPostgres == |
-> "archived" :! Bool | ||
-> ExceptT DatabaseError Transaction () | ||
updateCategoryArchived catId (arg #archived -> archived) = do | ||
isArchived <- isCategoryArchived catId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"old_archived" and "new_archived" would be more consistent.
back/src/Guide/Markdown.hs
Outdated
instance Aeson.FromJSON MarkdownTree where | ||
parseJSON = Aeson.withObject "MarkdownTree" $ \o -> do | ||
txt <- o Aeson..: "text" | ||
prefix <- o Aeson..:? "prefix" Aeson..!= T.empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use ""
instead of T.empty
, I don't think there is a reason to not use overloaded strings here.
back/src/Guide/Types/Core.hs
Outdated
-- | Unwarp result to category or fail. | ||
resultToEither :: Aeson.Result Category -> Category | ||
resultToEither (Aeson.Success category) = category | ||
resultToEither (Aeson.Error s) = error $ "fromJSON failed with error: " ++ s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, error
is verboten. Apparently we'll have to use jsonbBytes
after all because it would let us give back the decoding error (as Left
) without using error
.
761ee02
to
18cc4b9
Compare
Comment legaxy code
571cd92
to
77f839f
Compare
Resolve #389
This change is