[albums] Initial albums sorting by synchronization #299

Open
opened 2026-10-04 23:51:09 +02:00 by adam · 1 comment
Owner

Reported by jc on 1 Feb 2015 16:42

Version: 2.7.3

When synchronization running a new directories/albums are learnt from filesystem by get_fs_directories function in admin/include/functions.php. It use readdir PHP function without any type of sorting. I tested it for some time and order of this dirs is pretty mysterious. My tests was based on three directories (rok_01, rok_02, rok_03) and some experiments with mtimes, ctimes, inode numbers of directories and files. In all my tests i had rok_02 before rok_01. Don't know why, but i figured out how to do it better.

I changed get_fs_directories function to use glob PHP function instead of opendir/readdir/closedir. There is also usort, which sorts new categories by mtime (modify time) of corresponding directories.

Tested dot (hidden) directories and performance too. Speed is roughly the same (about 80 milliseconds for my 500 albums).

I think this is more logical and also very useful when importing a huge number of albums. For example i plan to change mtime of every dir based on information from Gallery2 SQL table so with some luck i will have the same album order like in original gallery.

Full function code attached and pasted to http://pastebin.com/TaPvryyh too.

Piwigo Bugtracker #3194

**Reported by jc on 1 Feb 2015 16:42** **Version:** 2.7.3 When synchronization running a new directories/albums are learnt from filesystem by get_fs_directories function in admin/include/functions.php. It use readdir PHP function without any type of sorting. I tested it for some time and order of this dirs is pretty mysterious. My tests was based on three directories (rok_01, rok_02, rok_03) and some experiments with mtimes, ctimes, inode numbers of directories and files. In all my tests i had rok_02 before rok_01. Don&#039;t know why, but i figured out how to do it better. I changed get_fs_directories function to use glob PHP function instead of opendir/readdir/closedir. There is also usort, which sorts new categories by mtime (modify time) of corresponding directories. Tested dot (hidden) directories and performance too. Speed is roughly the same (about 80 milliseconds for my 500 albums). I think this is more logical and also very useful when importing a huge number of albums. For example i plan to change mtime of every dir based on information from Gallery2 SQL table so with some luck i will have the same album order like in original gallery. Full function code attached and pasted to http://pastebin.com/TaPvryyh too. [Piwigo Bugtracker #3194](http://piwigo.org/bugs/view.php?id=3194) <!-- github-sync-id:97227026 -->
Author
Owner

Are there any news on this?
After every synchronization new albums are added in the wrong order (I use Z->A ordering)...
... can I help with this?

Are there any news on this? After every synchronization new albums are added in the wrong order (I use Z->A ordering)... ... can I help with this? <!-- github-comment-id:425410062 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#299