Closed aimeos closed 5 years ago
@s-diez Do you have an elegant solution for the emtpy file problem?
I would execute the first searchItems with a query for the total count and compare the exported items to it. I think this could simplify the logic. Additionally I would add a note about the relationship between 'max-items' and 'max-query' to the config description.
Maybe this is a good solution:
do
{
$items = $manager->searchItems( $search, $domains );
$free = $maxItems * $filenum - $start;
$count = count( $items );
if( $free < $count )
{
$this->addItems( $content, array_slice( $items, 0, $free, true ) );
$items = array_slice( $items, $free, null, true );
$this->closeContent( $content );
$content = $this->createContent( $container, ++$filenum );
$names[] = $content->getResource();
}
$this->addItems( $content, $items );
$start += $count;
$search->setSlice( $start, $maxQuery );
}
while( $count >= $search->getSliceSize() );
Yes, pointing readers in the docs to the fact that max-query must be smaller than max-items is a good idea :-)
@s-diez What do you think about the suggested code? Does it work for you?
I did run the unit tests with a couple of different 'max-query' and 'max-items' combinations. Seems to work fine.
Cool! Changes are added to the repo: https://github.com/aimeos/ai-controller-jobs/commit/30b2d49f7baaa06194204fd209eb1bebf8937dd6
The last empty file is probably due to creating a content item if there are no results any more: https://github.com/aimeos/ai-controller-jobs/pull/12/files#diff-6e026c9e50bd1a0a33f93cc4651ef1dfR362
If 'max-items' is 6, the first file should contain 6 items and the second 2 (maybe with an empty third file too). Maybe this was still the content of the old file or the configuration is still cached somewhere?
That's usually not a problem so we can keep it as is.