Skip to content
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

Add existsBy #1437

Merged
merged 9 commits into from
Mar 4, 2023
Merged

Add existsBy #1437

merged 9 commits into from
Mar 4, 2023

Conversation

blx
Copy link
Contributor

@blx blx commented Nov 4, 2022

This adds existsBy in PersistUniqueRead, as a more efficient version of isJust <$> getBy uniq.

The intent is to provide an (a) more convenient to type and (b) more efficient way to query existence of a row by unique key.

The SQL is a combination of the exists and getBy impls, and looks like SELECT EXISTS (SELECT 1 FROM ...constraints...).

The performance difference shouldn't be large, but conceivably on wider tables (or with heavy columns eg. JSON or binary blobs), existsBy would require less serialization (just a single response column) and may allow the query planner to do an index-only plan.

What do you think?


Before submitting your PR, check that you've:

  • Documented new APIs with Haddock markup
  • Added @since declarations to the Haddock
  • Ran stylish-haskell on any changed files.
  • Adhered to the code style (see the .editorconfig file for details)

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Bumped the version number if there isn't an (unreleased) on the Changelog
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

, parseEntityValues
, parseExistsResult
, updatePersistValue
)
Copy link
Contributor Author

@blx blx Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports diff here was just stylish-haskell, aside from adding parseExistsResult on line 27

@blx
Copy link
Contributor Author

blx commented Nov 5, 2022

CI is failing with a bunch of

Database/MongoDB/Query.hs:1692:32: error:
Error:     Not in scope: type constructor or class ‘MonadFail’
     |
1692 | aggregateCursor :: (MonadIO m, MonadFail m) => Collection -> Pipeline -> AggregateConfig -> Action m Cursor
     |                                ^^^^^^^^^

Database/MongoDB/Query.hs:1711:18: error:
Error:     Not in scope: type constructor or class ‘MonadFail’
     |
1711 |   :: (MonadIO m, MonadFail m)
     |                  ^^^^^^^^^

which looks like it's the mongoDB third-party package which I haven't touched here.

I wonder, if I hadn't edited anything in persistent-mongoDB here, would the CI have passed with pre-existing cached artifacts, or something, and not have run into any issues here?

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put a default impl on the class so it's a safer for backwards compatibility

persistent/Database/Persist/Class/PersistUnique.hs Outdated Show resolved Hide resolved
persistent-mongoDB/Database/Persist/MongoDB.hs Outdated Show resolved Hide resolved
@blx blx requested a review from parsonsmatt January 11, 2023 04:30
## 2.14.4.4

* [#1460] https://github.com/yesodweb/persistent/pull/1460
* [#1460](https://github.com/yesodweb/persistent/pull/1460)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the format in the rest of the changelog, where the PR number links to the link, but the URL itself is not shown. I can revert these changes if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great - thank you!

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you so much!

## 2.14.4.4

* [#1460] https://github.com/yesodweb/persistent/pull/1460
* [#1460](https://github.com/yesodweb/persistent/pull/1460)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great - thank you!

@parsonsmatt parsonsmatt merged commit d35142c into yesodweb:master Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants