cfculhane / AnkiOCR

Anki Addon to create searchable text from images in notes, using Tesseract OCR
MIT License
17 stars 5 forks source link

cannot run on more than 1000 cards #16

Closed thiswillbeyourgithub closed 3 years ago

thiswillbeyourgithub commented 3 years ago

Hi,

In case you didn't know, there seems to be a limit to how many cards the user can send to AnkiOCR, it's a minor annoyance to me as I often share very large decks with colleagues.

Here's the error :

Error encountered during processing, attempting to stop AnkiOCR gracefully. > Error below: Traceback (most recent call last): File "/home/USERNAME/.local/share/Anki2/addons21/450181164/gui.py", line 54, in on_run_ocr ocr.run_ocr_on_notes(note_ids=selected_nids) File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 303, in run_ocr_on_notes notes_query = self.run_ocr_on_query(query=query_str) File "/home/USERNAME/.local/share/Anki2/addons21/450181164/ocr.py", line 266, in run_ocr_on_query notes_query = NotesQuery(col=self.col, query=query) File "", line 7, in init File "/home/USERNAME/.local/share/Anki2/addons21/450181164/api.py", line 216, in __post_init__ self.notes = [OCRNote(note_id=nid, col=self.col) for nid in self.col.findNotes(query=self.query)] File "anki/collection.py", line 453, in find_notes File "anki/rsbackend_gen.py", line 88, in search_notes File "anki/rsbackend.py", line 267, in _run_command anki.rsbackend.DBError: DBError { info: "SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some(\"Expression tree is too large (maximum depth 1000)\"))", kind: Other }

cfculhane commented 3 years ago

This looks like an anki database limition, I'll add a check when highlighting cards to warn the user and prevent the ugly crash.

thiswillbeyourgithub commented 3 years ago

Hello again. Your python skills are obviously far sharper than mine but I don't really understand why you would run into an issue like that. I created a very simple addon the other day that can run over seemingly infinite number of cards (+40k at least) so I think it's just due to the way you ask the db to provide the cards nid.

My code is dead simple but gives you an idea : https://github.com/thiswillbeyourgithub/HapaxPredator

It is actually a heavily shortened script from Glutanimate from the addon batch editing. So his code shows a way to modify a very large number of cards in a row. My addon doesn't modify cards but is very short to understand.

Hope it helps.

cfculhane commented 3 years ago

Thanks, I neglected to come back and edit it - I discovered the way I was querying the dB is inefficient, you are totally correct! I will re do my approach and get back to you. There is a limit on the db query, but I was forming the query by concatenating the note IDs needed, which is not the best way šŸ˜‚ thanks for the link to your code, I'll take a look at it!

On Tue, 2 Mar 2021, 7:56 pm thiswillbeyourgithub, notifications@github.com wrote:

Hello again. Your python skills are obviously far sharper than mine but I don't really understand why you would run into an issue like that. I created a very simple addon the other day that can run over seemingly infinite number of cards (+40k at least) so I think it's just due to the way you ask the db to provide the cards nid.

My code is dead simple but gives you an idea : https://github.com/thiswillbeyourgithub/HapaxPredator

It is actually a heavily shortened script from Glutanimate from the addon batch editing https://ankiweb.net/shared/info/291119185. So his code shows a way to modify a very large number of cards in a row. My addon doesn't modify cards but is very short to understand.

Hope it helps.

ā€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cfculhane/AnkiOCR/issues/16#issuecomment-788740298, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRYIUZWGLAECSEMZZLEQRTTBSR2NANCNFSM4W4WIV6Q .

cfculhane commented 3 years ago

Sorry for the delay on this - but this is now fixed, will be pushing a release to AnkiWeb shortly.