-
-
Notifications
You must be signed in to change notification settings - Fork 213
Fix Dbafs::addResource and native record order. #7440
Conversation
AFAIU, |
They must sort in an order, that the parent directories comes first. And if I'm not wrong, the parent paths are always shorter than their children pathes ;-) |
What if there are multiple paths in $arrPaths = array(
'files/Media',
'files/Media/Images',
'files/Media/Images/Bild.jpg',
'files/Audio/RidiculouslyLongDirectoryName'
); I didn't test it yet, so this is a theoretical question. Your second idea to move the if condition inside the while loop seems to be the better choice anyways. |
How could that be in the I think your example is absolutely theoretically, but if this would be possible, my fix won't work properly, right. |
That's why I said "I didn't test it yet, so this is a theoretical question" :) So, which one of the fixes do you prefer? Order by path or move the if condition inside the while loop? |
I'd vote for moving the condition into the I guess it will be faster to compare all resulting models in PHP than letting MySQL first filter all of them by path (causing a string compare on each of them) and than letting MySQL finally sort them by the exact same string (causing yet another string compare on them). However, I also have not put any test on this to proof my guess. |
👍 |
Fixed in b11d911 then. |
If the native record order does not match the paths order, the
Dbafs::addResource
returnnull
.Short example:
In the database, the records in native order:
This situation may happen, when you first create
Bild.jpg
in another directory, and then move it into a directory that is created later.Then
\FilesModel::findMultipleByPaths($arrPaths)
will return:But the following logic will only work if the last item in the collection is the final file model.
Another solution may be to move the if condition into the while loop, like this: