Yeah, 1277 is definitely too many

. Actually, probably several hundred is too many, so I'm going to have to figure out some heuristics to cut down on the tags more. The note about large collections being slow is very good to know---I went back and chopped some tags that swept up too many books, so my largest collection is now ~150 books. I need to refine further, since my non-AO3 tags generate another 300+ (though some of those tags can be merged by normalizing capitalization).
At the moment, I'm using a very crude approach: I've created a custom column, and I have two scripts that literally invoke calibredb repeatedly. The AO3 script handles AO3 tags directly (bypassing the epub) and only calls calibredb to look up the calibre id and then to run calibredb set_metadata. The non-AO3 script looks up the Tags column and then runs calibredb set_metadata to add some of them to the custom column. This is slow and awkward, so I'd really like to write a plugin to do it instead. I spent some time looking through the API documentation for plugins, but I didn't see any discussion of how to write a plugin that does the kinds of things I want here. Does anyone know of a good example plugin that could get me started or some other resource that would help me?