Citation Popup: Search through the list of references using a given query#12
Citation Popup: Search through the list of references using a given query#12
Conversation
laurent22
left a comment
There was a problem hiding this comment.
Nice to see you are making good progresses. While you develop, could you also test that your code works with large BibTex files? I would suggest finding a 1GB file and see how it performs as that would be a good way to stress test your code. It's better to do this from time to time as you make progresses, because it will inform how you should develop certain parts of the plugin.
|
|
Regarding the difference between maps and plain js objects, it turns out that objects are much faster than maps in initialization and assigning values to keys. Objects are not as flexible as maps, but, in this situation, I don't that much flexibility (e.g getSize(), delete()); I only need to add key-value pairs and then look up the reference that corresponds to a given key. In conclusion, plain objects are better suited for this task. |
|
I've replaced the map with a plain js object and fixed minor UI bugs. |
That's all you need:
|
But I don't have access to
const li = document.createElement("li");
li.textContent = ref["id"]; // Auto-escaping |
All these options are fine so it's up to you. |
|
| waits until all the other scripts get loaded by Joplin, | ||
| and then starts doing its job | ||
| */ | ||
| setTimeout(main, 5, 10); |
There was a problem hiding this comment.
You should poll for what you need instead, because this hack might work on some computers but not others, if they are too slow for example.
const intervalId = setInterval(() => {
if (typeof he !== 'undefined') {
clearInterval(intervalId);
main();
}
}, 500);There was a problem hiding this comment.
By the way it's normal scripts might not be immediately available. This is like a web page and everything is loaded asynchronously.
| const invertedRefsIndex = {}; | ||
| refs.forEach(ref => invertedRefsIndex[ ref["id"] ] = ref); |
There was a problem hiding this comment.
Is that again for optimisation purposes? Because I'm certain it makes no difference. If you need a ref by ID, just use refs.find(r => r.id === refId). Duplicated data is always a bad idea because it needs to be kept in sync.
| // Modify Results Item Content | ||
| item.innerHTML = ` | ||
| <span style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;"> | ||
| ${ data.match } |
There was a problem hiding this comment.
Shouldn't you escape this too?
There was a problem hiding this comment.
OH, I forgot to mention that data.match is a DOM element that's responsible for highlighting the parts of the title that match the search query, so we can assume that it does escaping by default (I guess because it uses textContent internally). Also, it didn't break when I used the title 'This is an <art".
| function main () { | ||
|
|
||
| /* State */ | ||
| const refs = JSON.parse( he.decode(inputRefsView.textContent) ); |
There was a problem hiding this comment.
I don't think you need to decode here - textContent is plain text, not HTML.
| ); | ||
|
|
||
| const refs: Reference[] = DataStore.getAllReferences(); | ||
| html = html.replace("<!-- content -->", fromRefsToHTML(refs)); |
There was a problem hiding this comment.
By the way, did you check how it works with a 1GB file?
What has been doneOK, I've removed the use of the dictionary, replaced Stress testIn addition to the above tasks, I stress tested the code with large MethodI couldn't find a BibTeX file with 1GB of data so I downloaded this file. After that, I wrote a script that makes another copy of the file and then starts duplicating its contents over and over again until it reaches a certain size that I specify. Machine specs
ResultsAfter adjusting the size parameter and observing what happens to the plugin when I execute the main command, I came up with the following conclusions:
|
|
Looks good now, let's merge. Regarding the stress test, could you put this into a new issue instead please? (otherwise the info will be lost once the PR is closed) |


What has been done
Demo
Bugs
The following bugs still need to be solved: