imp run: More successful cache hits with forecast
If forecast start and end dates are explicitly requested with --forecast=, those parts of the reportspan_ can be replaced with the forecast dates, meaning more successful cache hits.
This commit is contained in:
parent
133560aa93
commit
8474c811c5
@ -43,7 +43,6 @@ import Hledger.Cli.DocFiles (runTldrForPage, runInfoForTopic, runManForTopic)
|
|||||||
import Hledger.Cli.Utils (journalTransform)
|
import Hledger.Cli.Utils (journalTransform)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import System.Process (system)
|
import System.Process (system)
|
||||||
import Data.Maybe (isJust)
|
|
||||||
|
|
||||||
-- | Command line options for this command.
|
-- | Command line options for this command.
|
||||||
runmode = hledgerCommandMode
|
runmode = hledgerCommandMode
|
||||||
@ -245,10 +244,19 @@ withJournalCached defaultJournalOverride cliopts cmd = do
|
|||||||
journal <- runExceptT $ if snd (splitReaderPrefix fp) == "-" then readStdin else readJournalFile iopts fp
|
journal <- runExceptT $ if snd (splitReaderPrefix fp) == "-" then readStdin else readJournalFile iopts fp
|
||||||
either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal
|
either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal
|
||||||
where
|
where
|
||||||
-- InputOptions contain reportspan_ that is used to calculare forecast period,
|
-- InputOptions contain reportspan_ that is used to calculate forecast period,
|
||||||
-- that is used by journalFinalise to insert forecast transactions.
|
-- that is used by journalFinalise to insert forecast transactions.
|
||||||
-- For the purposes of caching, we want to ignore this when --forecast is not given.
|
-- For the purposes of caching, we want to ignore it whenever
|
||||||
ioptsWithoutReportSpan = if isJust (forecast_ iopts) then iopts else iopts { reportspan_ = emptydatespan }
|
-- --forecast is not used, or when explicit dates are requested.
|
||||||
|
ioptsWithoutReportSpan = iopts{ reportspan_ = forecastreportspan }
|
||||||
|
where
|
||||||
|
forecastreportspan = case forecast_ iopts of
|
||||||
|
Nothing -> emptydatespan
|
||||||
|
-- This could be better if we had access to the journal (as we
|
||||||
|
-- could use 'forecastPeriod') or to the journal end date (as
|
||||||
|
-- forecast transactions are never generated before journal end
|
||||||
|
-- unless specifically requested).
|
||||||
|
Just forecastspan -> forecastspan `spanDefaultsFrom` reportspan_ iopts
|
||||||
-- Read stdin, or if we read it alread, use a cache
|
-- Read stdin, or if we read it alread, use a cache
|
||||||
-- readStdin :: InputOpts -> ExceptT String IO Journal
|
-- readStdin :: InputOpts -> ExceptT String IO Journal
|
||||||
readStdin = do
|
readStdin = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user