-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store ghc version for each snippet #24
base: master
Are you sure you want to change the base?
Conversation
Haven't built or tested locally, but from reading the code, this looks good so far. :) Thanks! |
Something that I thought of (not sure if this is still applicable after your last commit): I'm not sure I'd like the string "default" to ever appear in a |
I've made the ghcVersion column nullable and left it empty if it's not a supported version. |
Co-authored-by: Piotr Lewandowski <[email protected]>
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.
Honestly, can't really say much about the code, but you requested a review.
Anyway, thanks for the fix :)
Oh oops -- apparently I do not get notifications of PRs being set to "ready for review", and I'd missed most of what happened here completely. Sorry for the silence. I'll try to review this either today or early next week. |
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.
Disclaimer: I didn't test yet! Just looked at the code in the PR here.
Mostly looks good, couple of small things. Perhaps you can have a look at those? If you have no time any more I can also address them if you want.
@@ -71,6 +69,7 @@ schemaVersion :: Int | |||
,"CREATE TABLE pastes (\n\ | |||
\ id INTEGER PRIMARY KEY NOT NULL, \n\ | |||
\ key BLOB NOT NULL, \n\ | |||
\ ghcVersion TEXT, \n\ |
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 add an explicit NULL
after TEXT
preload_ghc_version = {{&version}}; | ||
{{/version}} | ||
{{^preload_ghc_version}} | ||
preload_ghc_version = "default"; |
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 don't like the in-band signalling here very much. I think it would be better if the "default" signal was null
instead. null
here would correspond to NULL
in the database.
|
||
UPDATE meta SET version = 6; | ||
|
||
ALTER TABLE pastes ADD COLUMN ghcVersion 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.
Also add an explicit NULL
here after TEXT
const snippet = preload_script != null ? preload_script : example_snippets[Math.floor(Math.random() * example_snippets.length)]; | ||
if (preload_ghc_version == "default") { | ||
preload_ghc_version = defaultGHCversion | ||
} |
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.
When switching away from "default"
, this whole if-statement can go :)
else do body <- readRequestBody (fromIntegral @Int @Word64 maxSaveFileSize) | ||
let body' = BSL.toStrict body | ||
let contents = Contents [(Nothing, body')] Nothing Nothing | ||
then lift $ httpError 429 "Please slow down a bit, you're rate limited" |
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.
when isSpam $ do
lift $ httpError 429 "Please slow down a bit, you're rate limited"
exitEarly ()
postdata <- ...
_ -> do lift (httpError 400 "Invalid JSON") | ||
exitEarly () | ||
versions <- liftIO (WP.getAvailableVersions (ctxPool ctx)) | ||
let version' = fromMaybe defaultGHCVersion $ Just <$> L.find (==version) versions |
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.
So this evaluates to fromMaybe Nothing (fmap Just x)
, which is equivalent to x
. I get that you want to abstract defaultGHCVersion
out, but since the intuitive semantics of Maybe
correspond quite nicely with what is meant here ("Nothing
indicates no version specified"), an alternative is to embrace the Maybe
, remove defaultGHCVersion
(which doesn't really yield a default version, it yields no version which is typically interpreted as meaning some default version), and simplify this to L.find (==version) versions
. Which, by the way, is a nice trick.
let contents = Contents [(Nothing, body')] Nothing Nothing | ||
then lift $ httpError 429 "Please slow down a bit, you're rate limited" | ||
else do postdata <- getRequestBodyEarlyExit maxSaveFileSize "Program too large" | ||
ClientSavePasteReq{csprCode =code, csprVersion = version} <- case J.decodeStrict' postdata of |
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.
missing space after =
const readable = versions[i] in ghcReadableVersion ? ghcReadableVersion[versions[i]] : versions[i]; | ||
opt.textContent = "GHC " + readable; | ||
if (versions[i] == defaultGHCversion) opt.setAttribute("selected", ""); | ||
let readable = versions[i] in ghcReadableVersion ? ghcReadableVersion[versions[i]] : versions[i]; |
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 reason for readable
to become non-const
, right?
if (versions[i] === defaultGHCversion) { | ||
verAnnotation = "(Default) " | ||
} | ||
opt.textContent = verAnnotation + "GHC " + readable; |
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 I prefer the annotation to come at the end, so GHC <version> (Default)
. Then the entries in the list all start in a uniform way (with GHC
).
|
||
versionToMustache :: Maybe Version -> Mustache.Value | ||
versionToMustache = \case | ||
Just ( Version v) -> toMustache v |
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.
Superfluous space after (
.
Also, versionToMustache = mixinMaybeNull (\(Version v) -> v)
if I'm not mistaken.
Proposed changes
Contributor checklist