-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PageIndex uses get_ftoc for cached ftocs to reduce load time
- Loading branch information
Showing
4 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import pytest | ||
import flask | ||
from datetime import datetime | ||
import otterwiki | ||
import otterwiki.gitstorage | ||
|
||
|
@@ -252,3 +253,31 @@ def test_get_pagename_prefixes(test_client): | |
'Example', | ||
'Random page', | ||
] | ||
|
||
|
||
def test_ftoc_cache(create_app, req_ctx): | ||
assert create_app | ||
assert req_ctx | ||
from otterwiki.helper import get_ftoc, update_ftoc_cache | ||
|
||
mtime = datetime.fromtimestamp(0) | ||
filename = "ftoc.md" | ||
ftoc = [ | ||
[0, "Ftoc", 1, "Ftoc", "ftoc"], | ||
[1, "Header 2", 2, "Header 2", "header-2"], | ||
[2, "Header 3", 3, "Header 3", "header-3"], | ||
] | ||
update_ftoc_cache(filename=filename, ftoc=ftoc, mtime=mtime) | ||
assert get_ftoc(filename=filename, mtime=mtime) == ftoc | ||
# store the file | ||
assert True == create_app.storage.store( | ||
filename, | ||
content="# Header 1\n\n## Header 2", | ||
author=("John", "[email protected]"), | ||
message=f"added {filename}", | ||
) | ||
|
||
assert [ | ||
(0, 'Header 1', 1, 'Header 1', 'header-1'), | ||
(1, 'Header 2', 2, 'Header 2', 'header-2'), | ||
] == get_ftoc(filename) |