Why is this very simple UPDATE so much slower than the SELECT it contains?
Change to:

SELECT @ct := COUNT(*) FROM photos;
UPDATE counts SET countValue = @ct WHERE countName = 'photos';


Either have autocommit = ON, or at least don't put both statements in the same transaction.  This is to avoid locking counts while counting.

Also, countName should be the PRIMARY KEY.