Verified Commit 50f195e1 authored by Camil Staps's avatar Camil Staps 🚀

Optimisations in backend: perform allTypeSynonyms and alwaysUniquePredicate only once

parent 0a4636aa
Pipeline #39670 passed with stages
in 31 minutes and 29 seconds
Subproject commit 0a630efb18bf13b20007caa88fa5cf004a3b206b
Subproject commit 44f2e54d7cbf47407faf6d0618aecef224bbefa6
......@@ -71,11 +71,8 @@ derive JSONDecode Kind, Type, RequestCacheKey, TypeContext, TypeRestriction,
instance toString RequestCacheKey
where toString rck = toString $ toJSON rck
toRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)
toRequestCacheKey db r
# (alwaysUnique,db) = alwaysUniquePredicate db
# (allsyns,db) = allTypeSynonyms db
= (
toRequestCacheKey :: (String -> Bool) (Map Name [TypeDef]) !Request -> RequestCacheKey
toRequestCacheKey alwaysUnique allsyns r =
{ c_unify = snd <$>
prepare_unification True alwaysUnique allsyns <$>
(parseType o fromString =<< r.unify)
......@@ -90,7 +87,7 @@ toRequestCacheKey db r
, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core
, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps
, c_page = fromMaybe 0 r.page
}, db)
}
fromRequestCacheKey :: RequestCacheKey -> Request
fromRequestCacheKey k =
{ unify = concat <$> print False <$> unprepare <$> k.c_unify
......@@ -238,7 +235,9 @@ handle Nothing db w = (err InvalidInput "Couldn't parse input" Nothing, (Nothing
handle (Just request=:{unify,name,page}) db w
#! (start,w) = nsTime w
//Check cache
#! (key,db) = toRequestCacheKey db request
#! (alwaysUnique,db) = alwaysUniquePredicate db
#! (allTypeSyns,db) = allTypeSynonyms db
#! key = toRequestCacheKey alwaysUnique allTypeSyns request
#! (mbResponse, w) = readCache key w
| isJust mbResponse
# r = fromJust mbResponse
......@@ -259,10 +258,10 @@ handle (Just request=:{unify,name,page}) db w
#! results = [r \\ r <|- Drop drop_n res]
#! more = max 0 (length results - MAX_RESULTS)
// Suggestions
#! (db,w) = seqSt
(\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))
#! w = seqSt
(\(req,res) w -> cachePages (toRequestCacheKey alwaysUnique allTypeSyns req) CACHE_PREFETCH 0 zero res w)
(fromMaybe [] suggs)
(db,w)
w
#! suggs = sortBy ((<) `on` snd) <$> map (appSnd length) <$> suggs
#! (results,nextpages) = splitAt MAX_RESULTS results
// Response
......
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