mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
Cache the Links in a note
This requires the markdown to be parsed which can be an incredibly slow operation, so lets avoid re-doing it unless necessary.
This commit is contained in:
@ -49,7 +49,9 @@ class Note with NotesNotifier {
|
|||||||
var _loadState = NoteLoadState.None;
|
var _loadState = NoteLoadState.None;
|
||||||
var _serializer = MarkdownYAMLCodec();
|
var _serializer = MarkdownYAMLCodec();
|
||||||
|
|
||||||
|
// Computed from body
|
||||||
String _summary;
|
String _summary;
|
||||||
|
List<Link> _links;
|
||||||
|
|
||||||
static final _mdYamlDocLoader = MdYamlDocLoader();
|
static final _mdYamlDocLoader = MdYamlDocLoader();
|
||||||
|
|
||||||
@ -109,6 +111,7 @@ class Note with NotesNotifier {
|
|||||||
set body(String newBody) {
|
set body(String newBody) {
|
||||||
_body = newBody;
|
_body = newBody;
|
||||||
_summary = null;
|
_summary = null;
|
||||||
|
_links = null;
|
||||||
_notifyModified();
|
_notifyModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,6 +374,10 @@ class Note with NotesNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Link>> fetchLinks() async {
|
Future<List<Link>> fetchLinks() async {
|
||||||
|
if (_links != null) {
|
||||||
|
return _links;
|
||||||
|
}
|
||||||
|
|
||||||
final doc = md.Document(
|
final doc = md.Document(
|
||||||
encodeHtml: false,
|
encodeHtml: false,
|
||||||
extensionSet: md.ExtensionSet.gitHubFlavored,
|
extensionSet: md.ExtensionSet.gitHubFlavored,
|
||||||
@ -392,11 +399,11 @@ class Note with NotesNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doc.linkReferences.forEach((key, value) {
|
doc.linkReferences.forEach((key, value) {
|
||||||
print(value);
|
|
||||||
var filePath = value.destination;
|
var filePath = value.destination;
|
||||||
links.add(Link(term: key, filePath: filePath));
|
links.add(Link(term: key, filePath: filePath));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_links = links;
|
||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user