From a3d2c7bb58f3e07655af8d70d77eb606cc25b704 Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Thu, 6 Mar 2025 22:09:31 +0000 Subject: [PATCH] ;run: test that demonstrates caching --- hledger/Hledger/Cli/Commands/Run.hs | 5 ++--- hledger/test/run.test | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Run.hs b/hledger/Hledger/Cli/Commands/Run.hs index 5ce0125de..9d3a79ff6 100644 --- a/hledger/Hledger/Cli/Commands/Run.hs +++ b/hledger/Hledger/Cli/Commands/Run.hs @@ -229,14 +229,13 @@ withJournalCached defaultJournalOverride cliopts cmd = do -- it separately. readAndCacheJournalFile :: InputOpts -> PrefixedFilePath -> IO Journal readAndCacheJournalFile iopts fp = do - dbg1IO "readAndCacheJournalFile" fp modifyMVar journalCache $ \cache -> case Map.lookup (ioptsWithoutReportSpan,fp) cache of Just journal -> do - dbg1IO "readAndCacheJournalFile using cache" (fp, iopts) + dbg1IO ("readAndCacheJournalFile using cache for "++fp) iopts return (cache, journal) Nothing -> do - dbg1IO "readAndCacheJournalFile reading and caching journals" (fp, iopts) + dbg1IO ("readAndCacheJournalFile reading and caching "++fp) iopts journal <- runExceptT $ if snd (splitReaderPrefix fp) == "-" then readStdin else readJournalFile iopts fp either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal where diff --git a/hledger/test/run.test b/hledger/test/run.test index cc1d25924..434ff7f91 100644 --- a/hledger/test/run.test +++ b/hledger/test/run.test @@ -149,3 +149,18 @@ Assets, depth 2: $-2 assets:cash -------------------- $-1 + +# ** 0. Run caches input files, and re-parses files when InputOptions change +< +2017-01-01 groceries + assets:cash -$100 + expenses:food +$ hledger run --debug 1 -f- -- accounts -- balance -f sample.journal -- balance cash --forecast -- balance cash -f sample.journal --forecast -- register -- register -f sample.journal 2>&1 | grep readAndCacheJournalFile | sed -e "s#$(pwd)/##" +> +readAndCacheJournalFile reading and caching -: +readAndCacheJournalFile using cache for -: +readAndCacheJournalFile reading and caching sample.journal: +readAndCacheJournalFile reading and caching -: +readAndCacheJournalFile reading and caching sample.journal: +readAndCacheJournalFile using cache for -: +readAndCacheJournalFile using cache for sample.journal: