Save ended sessions to the database