-
Notifications
You must be signed in to change notification settings - Fork 848
[WIP]Caching exposed modules for Hackage packages in Pantry DB #4624
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,10 +47,15 @@ module Pantry.Storage | |
| , loadCabalBlobKey | ||
| , hpackToCabal | ||
| , countHackageCabals | ||
| , storeExposedModules | ||
| , loadHasCachedExposedModules | ||
| , storeHasCachedExposedModules | ||
| , loadHackageExposedModules | ||
|
|
||
| -- avoid warnings | ||
| , BlobId | ||
| , HackageCabalId | ||
| , HackageExposedModulesId | ||
| , HackageTarballId | ||
| , CacheUpdateId | ||
| , FilePathId | ||
|
|
@@ -62,6 +67,7 @@ module Pantry.Storage | |
| , UrlBlobId | ||
| ) where | ||
|
|
||
| import Data.List.Extra (chunksOf) | ||
| import RIO hiding (FilePath) | ||
| import RIO.Process | ||
| import qualified RIO.ByteString as B | ||
|
|
@@ -134,8 +140,17 @@ HackageCabal | |
| -- If available: the full tree containing the HackageTarball | ||
| -- contents with the cabal file modified. | ||
| tree TreeId Maybe | ||
| -- If available should be equal to True meaning that | ||
| -- exposed modules were saved in HackageExposedModules | ||
| hasExposedModules Bool Maybe | ||
| UniqueHackage name version revision | ||
|
|
||
| -- Cache of modules exposed by a Hackage package | ||
| HackageExposedModules | ||
| cabal BlobId | ||
| moduleName P.ModuleNameP | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are likely to be a lot of duplicated module names, this would probably benefit from normalization, the same way we normalize package names. How about: Or something like that? |
||
| UniqueHackageExposedModules cabal moduleName | ||
|
|
||
| -- Any preferred-version information from Hackage | ||
| PreferredVersions | ||
| name PackageNameId | ||
|
|
@@ -379,6 +394,7 @@ storeHackageRevision name version key = do | |
| , hackageCabalRevision = Revision (fromIntegral rev) | ||
| , hackageCabalCabal = key | ||
| , hackageCabalTree = Nothing | ||
| , hackageCabalHasExposedModules = Nothing | ||
| } | ||
|
|
||
| loadHackagePackageVersions | ||
|
|
@@ -1023,3 +1039,55 @@ countHackageCabals = do | |
| [] -> pure 0 | ||
| (Single n):_ -> | ||
| pure n | ||
|
|
||
| loadHasCachedExposedModules | ||
| :: (HasPantryConfig env, HasLogFunc env) | ||
| => [BlobId] | ||
| -> ReaderT SqlBackend (RIO env) [BlobId] | ||
| loadHasCachedExposedModules bids = | ||
| fmap concat $ forM (chunksOf sqliteListLimit bids) $ \bids' -> | ||
| mapMaybe go <$> selectList [HackageCabalCabal <-. bids'] [] | ||
| where | ||
| go e | v <- entityVal e, | ||
| Just True <- hackageCabalHasExposedModules v = | ||
| Just $ hackageCabalCabal v | ||
| | otherwise = | ||
| Nothing | ||
|
|
||
| -- SQLITE_MAX_VARIABLE_NUMBER is 999 by default, | ||
| -- see https://www.sqlite.org/limits.html | ||
| sqliteListLimit :: Int | ||
| sqliteListLimit = 500 | ||
|
|
||
| storeHasCachedExposedModules | ||
| :: (HasPantryConfig env, HasLogFunc env) | ||
| => [BlobId] | ||
| -> ReaderT SqlBackend (RIO env) () | ||
| storeHasCachedExposedModules bids = | ||
| forM_ (chunksOf sqliteListLimit bids) $ \bids' -> | ||
| updateWhere [HackageCabalCabal <-. bids'] | ||
| [HackageCabalHasExposedModules =. Just True] | ||
|
|
||
| storeExposedModules | ||
| :: (HasPantryConfig env, HasLogFunc env) | ||
| => [(BlobId, P.ModuleName)] | ||
| -> ReaderT SqlBackend (RIO env) () | ||
| storeExposedModules ms = | ||
| forM_ ms $ \(bid, m) -> | ||
| rawExecute | ||
| "INSERT OR IGNORE INTO hackage_exposed_modules(cabal, module_name)\n\ | ||
| \VALUES (?, ?)" | ||
| [toPersistValue bid, toPersistValue (P.ModuleNameP m)] | ||
|
|
||
| loadHackageExposedModules | ||
| :: (HasPantryConfig env, HasLogFunc env) | ||
| => [BlobId] | ||
| -> ReaderT SqlBackend (RIO env) [(BlobId, P.ModuleName)] | ||
| loadHackageExposedModules bids = | ||
| fmap concat $ forM (chunksOf sqliteListLimit bids) $ \bids' -> | ||
| map go <$> selectList [HackageExposedModulesCabal <-. bids'] [] | ||
| where | ||
| go e = | ||
| let v = entityVal e | ||
| P.ModuleNameP m = hackageExposedModulesModuleName v | ||
| in (hackageExposedModulesCabal v, m) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we've been trying to avoid adding dependencies on these kinds of packages.