 modules/system/system.install |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git modules/system/system.install modules/system/system.install
index 0f6669f..1914bb3 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -2744,9 +2744,13 @@ function system_update_7059(&$sandbox) {
     }
   }
 
+  // Determine vids for this batch.
+  // Process all files attached to a given revision during same batch.
+  $limit = 100;
+  $vids = db_query('SELECT vid FROM {upload} WHERE u.vid > :lastvid GROUP BY vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']))->fetchCol();
+  
   // Migrate a batch of files from the upload table to the appropriate field.
-  $limit = 500;
-  $result = db_query_range('SELECT DISTINCT u.fid, u.vid, u.list, u.description, n.nid, n.type FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid > :lastvid ORDER BY u.vid, u.weight', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']));
+  $result = db_query_range('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight', 0, $limit, array(':vids' => $vids));
   foreach ($result as $record) {
     // Note that we still reference the old files table here, since upload will
     // not know about the new FID in the new file_managed table.
