add debug.clear-cache command · JavaDerek/unison@01163cc · GitHub
Skip to content

Commit 01163cc

Browse files
committed
add debug.clear-cache command
fix unisonweb#2090; only tests that it clears the regular watch cache, but it clears all.
1 parent af5895b commit 01163cc

14 files changed

Lines changed: 73 additions & 3 deletions

File tree

‎codebase2/codebase-sqlite/U/Codebase/Sqlite/Operations.hs‎

Lines changed: 3 additions & 0 deletions

‎codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ loadWatchesByWatchKind k = query sql (Only k) where sql = [here|
427427
SELECT hash_id, component_index FROM watch WHERE watch_kind_id = ?
428428
|]
429429

430+
clearWatches :: DB m => m ()
431+
clearWatches = do
432+
execute_ "DELETE FROM watch_result"
433+
execute_ "DELETE FROM watch"
434+
430435
-- * Index-building
431436
addToTypeIndex :: DB m => Reference' TextId HashId -> Referent.Id -> m ()
432437
addToTypeIndex tp tm = execute sql (tp :. tm) where sql = [here|

‎parser-typechecker/src/Unison/Codebase.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ data Codebase m v a =
9595
, watches :: UF.WatchKind -> m [Reference.Id]
9696
, getWatch :: UF.WatchKind -> Reference.Id -> m (Maybe (Term v a))
9797
, putWatch :: UF.WatchKind -> Reference.Id -> Term v a -> m ()
98+
, clearWatches :: m ()
9899

99100
, getReflog :: m [Reflog.Entry]
100101
, appendReflog :: Text -> Branch m -> Branch m -> m ()

‎parser-typechecker/src/Unison/Codebase/Editor/Command.hs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ data Command m i v a where
231231
RuntimeMain :: Command m i v (Type v Ann)
232232
RuntimeTest :: Command m i v (Type v Ann)
233233

234+
ClearWatchCache :: Command m i v ()
235+
234236
type UseCache = Bool
235237

236238
type EvalResult v =
@@ -290,3 +292,4 @@ commandName = \case
290292
LoadSearchResults{} -> "LoadSearchResults"
291293
GetDefinitionsBySuffixes{} -> "GetDefinitionsBySuffixes"
292294
FindShallow{} -> "FindShallow"
295+
ClearWatchCache{} -> "ClearWatchCache"

‎parser-typechecker/src/Unison/Codebase/Editor/HandleCommand.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ commandLine config awaitInput setBranchRef rt notifyUser notifyNumbered loadSour
177177
GetDefinitionsBySuffixes mayPath branch query ->
178178
lift . runExceptT $ Backend.definitionsBySuffixes mayPath branch codebase query
179179
FindShallow path -> lift . runExceptT $ Backend.findShallow codebase path
180+
ClearWatchCache -> lift $ Codebase.clearWatches codebase
180181

181182
watchCache (Reference.DerivedId h) = do
182183
m1 <- Codebase.getWatch codebase UF.RegularWatch h

‎parser-typechecker/src/Unison/Codebase/Editor/HandleInput.hs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ loop = do
466466
DebugBranchHistoryI{} -> wat
467467
DebugTypecheckedUnisonFileI{} -> wat
468468
DebugDumpNamespacesI{} -> wat
469+
DebugClearWatchI {} -> wat
469470
QuitI{} -> wat
470471
DeprecateTermI{} -> undefined
471472
DeprecateTypeI{} -> undefined
@@ -1822,6 +1823,7 @@ loop = do
18221823
prettyDefn renderR (r, (Foldable.toList -> names, Foldable.toList -> links)) =
18231824
P.lines (P.shown <$> if null names then [NameSegment "<unnamed>"] else names) <> P.newline <> prettyLinks renderR r links
18241825
void . eval . Eval . flip State.execStateT mempty $ goCausal [getCausal root']
1826+
DebugClearWatchI {} -> eval ClearWatchCache
18251827
DeprecateTermI {} -> notImplemented
18261828
DeprecateTypeI {} -> notImplemented
18271829
RemoveTermReplacementI from patchPath ->

‎parser-typechecker/src/Unison/Codebase/Editor/Input.hs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ data Input
137137
| DebugBranchHistoryI
138138
| DebugTypecheckedUnisonFileI
139139
| DebugDumpNamespacesI
140+
| DebugClearWatchI
140141
| QuitI
141142
deriving (Eq, Show)
142143

‎parser-typechecker/src/Unison/Codebase/FileCodebase.hs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import Unison.Codebase.FileCodebase.Common
6767
typeMentionsIndexDir,
6868
typeReferencesByPrefix,
6969
updateCausalHead,
70-
watchesDir,
70+
watchesDir, codebasePath
7171
)
7272
import qualified Unison.Codebase.FileCodebase.Common as Common
7373
import qualified Unison.Codebase.FileCodebase.SlimCopyRegenerateIndex as Sync
@@ -90,7 +90,7 @@ import qualified Unison.Util.Pretty as P
9090
import qualified Unison.Util.TQueue as TQueue
9191
import U.Util.Timing (time)
9292
import Unison.Var (Var)
93-
import UnliftIO.Directory (createDirectoryIfMissing, doesDirectoryExist)
93+
import UnliftIO.Directory (createDirectoryIfMissing, doesDirectoryExist, removeDirectoryRecursive)
9494
import UnliftIO.STM (atomically)
9595

9696
init :: (MonadIO m, MonadCatch m) => Codebase.Init m Symbol Ann
@@ -169,6 +169,7 @@ codebase1' syncToDirectory branchCache fmtV@(S.Format getV putV) fmtA@(S.Format
169169
watches
170170
(getWatch getV getA path)
171171
(putWatch putV putA path)
172+
(removeDirectoryRecursive $ path </> codebasePath </> "watches")
172173
getReflog
173174
appendReflog
174175
getTermsOfType

‎parser-typechecker/src/Unison/Codebase/SqliteCodebase.hs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ sqliteCodebase debugName root = do
623623
(Cv.term1to2 h tm)
624624
putWatch _unknownKind _ _ = pure ()
625625

626+
clearWatches :: MonadIO m => m ()
627+
clearWatches = runDB conn Ops.clearWatches
628+
626629
getReflog :: MonadIO m => m [Reflog.Entry]
627630
getReflog =
628631
liftIO $
@@ -755,6 +758,7 @@ sqliteCodebase debugName root = do
755758
watches
756759
getWatch
757760
putWatch
761+
clearWatches
758762
getReflog
759763
appendReflog
760764
termsOfTypeImpl

‎parser-typechecker/src/Unison/CommandLine/InputPatterns.hs‎

Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)