Num_files value in system api?

Hi,

I am wondering how the number of files on nextcloud instance is calculated ? We can get this value through UI (Settings > System) or through the OCS API with this endpoint : ocs/v2.php/apps/serverinfo/api/v1/info

I came across this topic but it hasn’t been answered so I am opening a new one.

I make the same observation as in this comment where I know fewer files are added than the difference shown with the API.

I don’t think it’s a bug but I would like very much to understand this metric. It could be the previews generation, trashbin, versions, etc. Does anyone know about it?

You should be able to find out more in the app’s code at GitHub - nextcloud/serverinfo: 📊 A monitoring app which creates a server info dashboard for admins

Thank you for referring me the right repo, it was not very clear to me where the different APIs were defined.

This metric is calculated in this function. It is based on the oc_filecache table and sums all the entries per storage (from oc_storages).

I was not able to find relevant information about the way oc_filecache is built but for my account (= my storage) I found in addition to the regular files :

  • files_trashbin/...
  • files_version/...
  • onlyoffice/... (cache files I guess)
  • files_encryption/... (which I do not use, I don’t know why they exist)
  • files_external/... (only rootcerts.crt)

To sum up, oc_filecache seems to be a tree where we have (depending on the activated apps) :

root
├── cache
├── files
│   └── foo.pdf
├── files_encryption
├── files_external
├── files_trashbin
├── files_versions
├── onlyoffice
└── uploads

and every node counts (even root).

Seems that none of the topics about this are complete or up to date with NC26.

Just to add as an info, for future visitors:

  • looking as admin, under Settings, Administration, System ( /index.php/settings/admin/serverinfo ) I see 773140 files which is information that’s a snapshot in time at some moment (running preview generation right now so files keep getting created, but this file is static)
  • on the filesystem running find . -type f | wc -l on my data folder (whole data) says 555807 files
  • doing same for everything including folders it gives 810858 items (files, folders)
  • checking oc_filecache few minutes before doing find gave 804k+, doing it later gave me 813761 rows (preview gen running so expected)

Thus I can conclude that “System” / “serverinfo” page stating " Files: 773140" is deceiving in multiple ways:

  • those are not files but files AND FOLDERS
  • it includes file thumbnails/previews that are indeed part of the filesystem and database, but are not files shown in the web interface (or otherwise through normal means in NC instance)
  • it includes trashbin, cache and all the temp files of assorted types
  • number is not refreshed very often and no obvious way to refresh manually

Doing find . -type f | wc -l on my actual “files” folder gives me “152307” so differences are astonishing.

Just as an info, cache of preview app alone holds 661698 files AND folders (folder appdata_ocpw4npcn95e/preview scanned using find . | wc -l )

To explain, I wanted to know how many FILES I had in my instance, so I could approximate how long the preview generation would take, in process I’ve found that most of it will be ignored anyway because ~80% of the number are thumbnails and folders of the preview itself.

Anyway, hope this helps someone else trying to get to the actual numbers like me. One would wish there was simply a file count for folders available in Files app under “Details”…