News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Question about converter code.......

Started by wing, July 29, 2005, 11:13:08 AM

Previous topic - Next topic

wing

What's the point of this?

If you have more than 100 entries it sticks them all in, then clears the array, if you have less it does the same.  I see no difference here?


if (count($block) > 100)
{
$insert_block = array();
foreach ($block as $row)
$insert_block[] = '\'' . implode('\', \'', addslashes_recursive($row)) . '\'';

mysql_query("INSERT INTO {$to_prefix}messages
(" . implode(', ', array_keys($block[0])) . ")
VALUES (" . implode("),
(", $insert_block) . ")");

$block = array();

      }
   if (!empty($block))
              {
$insert_block = array();
foreach ($block as $row)
$insert_block[] = '\'' . implode('\', \'', addslashes_recursive($row)) . '\'';


mysql_query("
INSERT INTO {$to_prefix}messages
(" . implode(', ', array_keys($block[0])) . ")
VALUES (" . implode("),
(", $insert_block) . ")");

}

unless I erased something I shouldn't have ........

[Unknown]

One (should be) inside the loop, one outside.

The idea is this.  Let's say you have 467 posts to convert.  Inserting ALL of them at once is obviously a bad idea, because it means that we have to convert and copy all of that data in one step.  Doing it in multiple steps makes it more likely the server won't have trouble, and the converter will continue properly.

So, every time it gets up to 100 posts, it flushes the "cache" to disk.  After this, it can stop (because the "todo list" is empty) temporarily and start back where it left off.

But, once it's done the first 400, there are only 67 left.  Once it leaves the loop (being done) it needs to flush out the remainder of the posts.

-[Unknown]

wing

#2
That's what I figured, but I see no loop.  ???

I'll check the code again, because if it's wrong the way I have it, when I convert it will dump in 60K of posts at once.

I must has deleted it, or that's a mistake in the converter (which I doubt).  :P

wing

Ok, I downloaded another copy of the script and see the loop.

It looks like your doing a sql query on the convertee, only taking 100 or so, then doing another query from where you left off.

It's all fine and dandy then, I'll have to figure out how to do it with mine.  What my code does is gets everything all at once from the webpages.  So what I'm going to have to do, is then loop through the entries in the array filling another array until 100 or so, probably make it 500.  Put them in and then continue from there.

Advertisement: