1
Fork 0
photoview/api/scanner
Lajos Koszti 1f8664d7f8
fix transaction already commited error
I encountered with the following error:

> 2023/02/05 07:33:00 /app/scanner/face_detection/face_detector.go:92 sql: transaction has already been committed or rolled back
> [0.042ms] [rows:0] SELECT * FROM `media` WHERE `media`.`id` = 823 ORDER BY `media`.`id` LIMIT 1
> 2023/02/05 07:33:00 ERROR: Error detecting faces in image (/photos/Borzsony2017/DSC_0028.NEF): sql: transaction has already been committed or rolled back

It turned out it comes from the api/routes/photos.go

I found a very similar code in album_scanner.go.
The difference I saw was that while in the single photo request the
transaction passed to the `scanner_tasks.Tasks.BeforeProcessMedia` call,
in the album_scann.go the transaction created after this call and
created from the context which returned by `BeforeProcessMedia`.

Another difference was that in the `ProcessSingleMedia` call the
`AfterProcessMedia` call was called with the same - db transaction -
context, in the album_scanner it was called outside of the transaction.

I changed the logic by merging the two behavior:
Create the transaction from the context of `BeforeProcessMedia` and also
use the transaction context in the `AfterProcessMedia`.
After the change the error disappeared.

So to have it in a common place I extracted that logic into a function
and use for both the single photo request and in the album scanner.

I did not go more deeper to find out what's going on with the context
under the hood.
2023-02-05 09:05:05 +01:00
..
exif Adding image description to sidebar 2022-03-28 16:08:30 +01:00
face_detection Hide faces from frontend if disabled 2021-08-31 12:05:46 +02:00
media_encoding Changed downsampling method to custom type. 2022-08-09 06:09:55 +01:00
media_type Add support for .CR3 photos. 2022-08-10 07:43:39 +01:00
periodic_scanner Start on big scanner code refactoring 2022-02-14 23:57:45 +01:00
scanner_cache Batch exiftool runs + scanner package restructuring 2021-05-06 22:01:48 +02:00
scanner_queue Fixed ScanAlbum failing silently. 2022-08-12 02:18:59 +01:00
scanner_task Fix API tests 2022-07-08 17:44:03 +02:00
scanner_tasks Introduce thumbnail filtering options. 2022-08-05 19:37:55 +01:00
scanner_utils Batch exiftool runs + scanner package restructuring 2021-05-06 22:01:48 +02:00
test_data Fix faces not getting scanned 2021-04-26 12:21:15 +02:00
media_scan.go fix transaction already commited error 2023-02-05 09:05:05 +01:00
scanner_album.go fix transaction already commited error 2023-02-05 09:05:05 +01:00
scanner_album_test.go Improve scanner_album NewRootPath tests 2021-04-26 20:37:29 +02:00
scanner_media.go fix transaction already commited error 2023-02-05 09:05:05 +01:00
scanner_test.go Add failing test for #198 2021-11-06 12:23:47 +01:00
scanner_user.go WIP: split up scanner into separate tasks 2022-02-15 17:22:41 +01:00
thumbnail_blurhash.go Integrate blurhashes with UI 2022-02-01 23:39:19 +01:00