We have had situations on h5p.org where the H5P package doesn't include all dependencies. This most probably happens because filtered is reset too early. Should do that when all library dependencies are saved. I.e: move https://github.com/h5p/h5p-php-library/blob/c4e52f4f29f3824dd69fbddeeb524ff1dade32aa/h5p.classes.php#L1498 out of the foreach-loop.
Ideally, this should be a single transaction which locks the table, but the above approach will at least improve the situation.