Fixed api performance. Added script to fix existing media ids in db