joplin / plugin-bibtex

Use locally stored BibTeX files to integrate citation into Joplin
30 stars 7 forks source link

Citation Popup: Search through the list of references using a given query #12

Closed xUser5000 closed 3 years ago

xUser5000 commented 3 years ago

What has been done

Demo

Demo

Bugs

The following bugs still need to be solved:

xUser5000 commented 3 years ago
xUser5000 commented 3 years ago

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.

xUser5000 commented 3 years ago

I've replaced the map with a plain js object and fixed minor UI bugs. Now my question is: How to implement escaping in view.js? Do I download a new library just for that or? I also want to know whether or not this is necessary because I already escape the JSON object passed to the view.

laurent22 commented 3 years ago

Now my question is: How to implement escaping in view.js?

That's all you need:

<li id="${encode(ref["id"])}">

xUser5000 commented 3 years ago

That's all you need:

<li id="${encode(ref["id"])}">

But I don't have access to html-entites from the view, so there are three options at hand:

laurent22 commented 3 years ago

But I don't have access to html-entites from the view, so there are three options at hand:

All these options are fine so it's up to you.

xUser5000 commented 3 years ago
xUser5000 commented 3 years ago

What has been done

OK, I've removed the use of the dictionary, replaced setTimeout() with setInterval(), and removed the redundant escaping in view.js.

Stress test

In addition to the above tasks, I stress tested the code with large .bib files. I already did a stress test with a ~300KB file, but this time I tried much larger files.

Method

I 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

Results

After adjusting the size parameter and observing what happens to the plugin when I execute the main command, I came up with the following conclusions:

laurent22 commented 3 years ago

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)