Deleting all entries from a Section I'm using Feedme to add entries via an external JSON feed.
There was an issue with matching duplicates and now need to remove >4000 entries from the site.

To avoid further issues would ideally like to build this into the feedme script we are running but the built-in delete method times out due to memory issues. I've looked at other ways we can achieve this, eg by deleting via the entries model:

$entriesRecord = EntryRecord::model()-&gt;findAllByAttributes(array('sectionId' =&gt; $sectionId));
$entriesRecord-&gt;delete();


But this is also timing out. Mike Pepper pointed me in the direction of the a&amp;m command add-on at https://github.com/am-impact/amcommand but this is also struggling. Is the only way to deal with such large quantities of entries to do this directly via SQL?

Help!
Records are definitely not the way to go with dealing with large amounts of data sets in the database.  There is just too much overheard associated with them.

Manually running SQL (as you've discovered) is an option, but if you wanted to do this from PHP, you could still use QueryBuilder.

$elementIds = craft()-&gt;db-&gt;createCommand()
            -&gt;select('id')
            -&gt;from('entries')
            -&gt;where('sectionId = :sectionId', array(':sectionId' =&gt; 18))
            -&gt;queryColumn();

$rowsAffected = craft()-&gt;db-&gt;createCommand()
            -&gt;delete(
                'elements',
                array('in', 'id', $elementIds)
             );


The MySQL cascading deletes setup on the foreign keys should take care of cleaning up the necessary rows in the remaining tables automatically.