Skip to content

Commit cb834a4

Browse files
committed
results ref is now a maybe, which is more accurate. printing file names actually works as expected
1 parent 34d5da4 commit cb834a4

File tree

6 files changed

+74
-46
lines changed

6 files changed

+74
-46
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ Currently via config you can:
5353
- Set files to ignore via a list of regular expressions
5454
- Specify your own flags to scan for other than the built-ins (TODO, FIXME, XXX)
5555

56+
#### Ignoring Files
57+
58+
Ignore as many files as you can! Large autogenerated files will slow Toodles
59+
down quite a bit. Check the output of the server to see any files/folders that
60+
may be causing slowness for your repo and add them to the `ignore` section your
61+
`.toodles.yaml` If the performance of Toodles is not good enough for your use
62+
case, please open an issue.
63+
5664
### Scanned Languages
5765

5866
These languages will be scanned for any TODO's:

app/Main.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ import Text.Printf (printf)
1616
main :: IO ()
1717
main = do
1818
userArgs <- toodlesArgs >>= setAbsolutePath
19-
sResults <- runFullSearch userArgs
2019
case userArgs of
21-
(ToodlesArgs _ _ _ _ True _) -> mapM_ (putStrLn . prettyFormat) $ todos sResults
20+
(ToodlesArgs _ _ _ _ True _) -> do
21+
sResults <- runFullSearch userArgs
22+
mapM_ (putStrLn . prettyFormat) $ todos sResults
2223
_ -> do
23-
let webPort = fromMaybe 9001 $ port userArgs
24-
ref <- newIORef sResults
25-
dataDir <- (++ "/web") <$> getDataDir
26-
putStrLn $ "serving on " ++ show webPort
27-
run webPort $ app $ ToodlesState ref dataDir
24+
let webPort = fromMaybe 9001 $ port userArgs
25+
ref <- newIORef Nothing
26+
dataDir <- (++ "/web") <$> getDataDir
27+
putStrLn $ "serving on " ++ show webPort
28+
run webPort $ app $ ToodlesState ref dataDir
2829

2930
prettyFormat :: TodoEntry -> String
3031
prettyFormat (TodoEntryHead _ l a p n entryPriority f _ _ _ _ _ _) =

src/Parse.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Data.Maybe (fromJust, fromMaybe, isJust,
1313
import Data.Text (Text)
1414
import qualified Data.Text as T
1515
import Data.Void (Void)
16-
import Debug.Trace
1716
import Text.Megaparsec
1817
import Text.Megaparsec.Char
1918
import qualified Text.Megaparsec.Char.Lexer as L
@@ -212,14 +211,14 @@ nextState a b = error ("No next state for " ++ show a ++ " " ++ show b)
212211
runTodoParser :: [UserFlag] -> SourceFile -> [TodoEntry]
213212
runTodoParser us (SourceFile path ls) =
214213
let parsedTodoLines =
215-
trace ("path done: " ++ path) $ foldl
214+
foldl
216215
(fileParseFoldFn
217216
us
218217
path)
219218
(ParseStateUnknown, [])
220219
(zip [1 ..] ls)
221220
groupedTodos = foldl foldTodoHelper ([], False) (snd parsedTodoLines)
222-
in trace path fst groupedTodos
221+
in fst groupedTodos
223222

224223
where
225224
-- fold fn to concatenate todos that a multiple, single line comments

src/Server.hs

+53-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
{-# LANGUAGE BangPatterns #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE ScopedTypeVariables #-}
4-
55
{-# LANGUAGE TypeOperators #-}
66

77
module Server where
@@ -67,13 +67,16 @@ root (ToodlesState _ dPath) path =
6767

6868
showRawFile :: ToodlesState -> Integer -> Handler Html
6969
showRawFile (ToodlesState ref _) eId = do
70-
(TodoListResult r _) <- liftIO $ readIORef ref
71-
let entry = find (\t -> entryId t == eId) r
72-
liftIO $
73-
maybe
74-
(return "Not found")
75-
(\e -> addAnchors <$> readFile (sourceFile e))
76-
entry
70+
storedResults <- liftIO $ readIORef ref
71+
case storedResults of
72+
(Just (TodoListResult r _)) -> do
73+
let entry = find (\t -> entryId t == eId) r
74+
liftIO $
75+
maybe
76+
(return "Not found")
77+
(\e -> addAnchors <$> readFile (sourceFile e))
78+
entry
79+
Nothing -> error "no files to show"
7780

7881
where
7982
addAnchors :: String -> Html
@@ -87,17 +90,20 @@ showRawFile (ToodlesState ref _) eId = do
8790

8891
editTodos :: ToodlesState -> EditTodoRequest -> Handler Text
8992
editTodos (ToodlesState ref _) req = do
90-
(TodoListResult r _) <- liftIO $ readIORef ref
91-
let editedList =
92-
map
93-
(\t ->
94-
if willEditTodo req t
95-
then editTodo req t
96-
else t)
97-
r
98-
editedFilteredList = filter (willEditTodo req) editedList
99-
_ <- mapM_ recordUpdates editedFilteredList
100-
return "{}"
93+
storedResults <- liftIO $ readIORef ref
94+
case storedResults of
95+
(Just (TodoListResult r _)) -> do
96+
let editedList =
97+
map
98+
(\t ->
99+
if willEditTodo req t
100+
then editTodo req t
101+
else t)
102+
r
103+
editedFilteredList = filter (willEditTodo req) editedList
104+
_ <- mapM_ recordUpdates editedFilteredList
105+
return "{}"
106+
Nothing -> error "no stored todos to edit"
101107
where
102108
willEditTodo :: EditTodoRequest -> TodoEntry -> Bool
103109
willEditTodo editRequest entry = entryId entry `elem` editIds editRequest
@@ -189,14 +195,17 @@ updateTodoLinesInFile f todo = do
189195

190196
deleteTodos :: ToodlesState -> DeleteTodoRequest -> Handler Text
191197
deleteTodos (ToodlesState ref _) req = do
192-
refVal@(TodoListResult r _) <- liftIO $ readIORef ref
193-
let toDelete = filter (\t -> entryId t `elem` ids req) r
194-
liftIO $ doUntilNull removeAndAdjust toDelete
195-
let remainingResults = filter (\t -> entryId t `notElem` map entryId toDelete) r
196-
let updatedResults = foldl (flip adjustLinesAfterDeletionOf) remainingResults toDelete
197-
let remainingResultsRef = refVal { todos = updatedResults }
198-
_ <- liftIO $ atomicModifyIORef' ref (const (remainingResultsRef, remainingResultsRef))
199-
return "{}"
198+
storedResults <- liftIO $ readIORef ref
199+
case storedResults of
200+
(Just refVal@(TodoListResult r _)) -> do
201+
let toDelete = filter (\t -> entryId t `elem` ids req) r
202+
liftIO $ doUntilNull removeAndAdjust toDelete
203+
let remainingResults = filter (\t -> entryId t `notElem` map entryId toDelete) r
204+
let updatedResults = foldl (flip adjustLinesAfterDeletionOf) remainingResults toDelete
205+
let remainingResultsRef = refVal { todos = updatedResults }
206+
_ <- liftIO $ atomicModifyIORef' ref (const (Just remainingResultsRef, Just remainingResultsRef))
207+
return "{}"
208+
Nothing -> error "no stored todos"
200209

201210
where
202211

@@ -239,14 +248,17 @@ setAbsolutePath args = do
239248
return $ args {directory = absolute}
240249

241250
getFullSearchResults :: ToodlesState -> Bool -> IO TodoListResult
242-
getFullSearchResults (ToodlesState ref _) recompute =
243-
if recompute
251+
getFullSearchResults (ToodlesState ref _) recompute = do
252+
result <- readIORef ref
253+
if recompute || isNothing result
244254
then do
245255
putStrLn "refreshing todo's"
246256
userArgs <- toodlesArgs >>= setAbsolutePath
247257
sResults <- runFullSearch userArgs
248-
atomicModifyIORef' ref (const (sResults, sResults))
249-
else putStrLn "cached read" >> readIORef ref
258+
atomicModifyIORef' ref (const (Just sResults, sResults))
259+
else do
260+
putStrLn "cached read"
261+
return $ fromMaybe (error "tried to read from the cache when there wasn't anything there") result
250262

251263
runFullSearch :: ToodlesArgs -> IO TodoListResult
252264
runFullSearch userArgs = do
@@ -259,8 +271,8 @@ runFullSearch userArgs = do
259271
$ putStrLn $ "[WARNING] Invalid .toodles.yaml: " ++ show config
260272
let config' = fromRight (ToodlesConfig [] []) config
261273
allFiles <- getAllFiles config' projectRoot
262-
let parsedTodos = concatMap (runTodoParser $ userFlag userArgs ++ flags config') allFiles
263-
filteredTodos = filter (filterSearch (assignee_search userArgs)) parsedTodos
274+
parsedTodos <- concat <$> mapM (parseFileAndLog userArgs config') allFiles
275+
let filteredTodos = filter (filterSearch (assignee_search userArgs)) parsedTodos
264276
resultList = limitSearch filteredTodos $ limit_results userArgs
265277
indexedResults = map (\(i, r) -> r {entryId = i}) $ zip [1 ..] resultList
266278
return $ TodoListResult indexedResults ""
@@ -274,6 +286,14 @@ runFullSearch userArgs = do
274286
limitSearch todoList 0 = todoList
275287
limitSearch todoList n = take n todoList
276288

289+
parseFileAndLog :: ToodlesArgs -> ToodlesConfig -> SourceFile -> IO [TodoEntry]
290+
parseFileAndLog userArgs config f = do
291+
-- the strictness is so we can print "done" when we're actually done
292+
!_ <- putStrLn $ fullPath f
293+
!result <- return (runTodoParser (userFlag userArgs ++ flags config) f)
294+
!_ <- putStrLn "done"
295+
return result
296+
277297
getAllFiles :: ToodlesConfig -> FilePath -> IO [SourceFile]
278298
getAllFiles (ToodlesConfig ignoredPaths _) basePath =
279299
E.catch

src/Types.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data SourceFile = SourceFile
2323
type LineNumber = Integer
2424

2525
data ToodlesState = ToodlesState
26-
{ results :: IORef TodoListResult,
26+
{ results :: IORef (Maybe TodoListResult),
2727
dataPath :: FilePath
2828
}
2929

web/html/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@
121121
<div class="main-container container content column is-three-quarters">
122122
<div class="loading-spinner" v-show="loading"><a class="button is-loading">Loading</a> Loading
123123
TODO's. If your project is large, this can take a few moments.
124-
Try configuring toodles to ignore large and/or autogenerated
125-
files.
124+
Try configuring toodles to ignore large, autogenerated, or
125+
third-party files.
126126
<a target="_blank" href="https://github.com/aviaviavi/toodles/blob/master/.toodles.yaml">More info on configuring toodles</a>
127127
</div>
128128
<table class="table todo-list is-striped is-hoverable">

0 commit comments

Comments
 (0)