As raised by @Berdir in 2853480, at scale, this is currently inefficient:

+++ b/src/ContactStorageExportBatches.php
@@ -124,35 +124,22 @@ class ContactStorageExportBatches {
 
       // Add the row to our CSV data.
-      $context['results']['data'][] = $row;
+      $context['results']['data'][] = $serialized_message;
Note that with enough messages, you could still run into problems here. Actually, possibly even more likely. what you are doing is storing all those values into the batch storage, so every batch request has to load it from the DB and store it back.

A better approach is what we're doing in views_data_export with the bulk support, where each batch run directly appends to the file.

I've discussed this with @mbovan, and we were surprised to not see an option to suppress the headers for CSV, but we could always cut off the first line again.

So our suggestion is basically to keep it like this for now, and then have another follow-up issue to look into changing. that. We could instead use the encode() method on the new service, that would directly return the CSV string, thta we could then append to a file.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scott_euser created an issue. See original summary.

scott_euser’s picture

Related to #2854087

scott_euser’s picture

Status: Active » Needs review
FileSize
8.77 KB

Here is the updated code to write to a tempfile as it progresses.
As far as I can see, the tempfile is not accessible publicly so I don't think it poses a security issue.

  • scott_euser committed c2df4df on 8.x-1.x
    Issue #2854083 by scott_euser: Write and append directly to a temp file...
scott_euser’s picture

Status: Needs review » Fixed
scott_euser’s picture

Issue tags: +DrupalCampLDN

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.