Automatically schedule a photos re-index on your Synology NAS to add missing images

If you've been having trouble getting Synology Photos to more consistently show newly added images and videos, this might be of use to you.

Automatically schedule a photos re-index on your Synology NAS to add missing images

The Synology Photos app that came with the big DSM7 upgrade is pretty nice overall. It bridges the gap between Synology Moments and PhotoStation and, even though I don't think it actually covers all of the same features, it creates a more coherent package, with a single place for you to find your photos. Whether they're imported phone snaps, family photos, or your DLSR archives.

If you're using the /photo shared directory to also manually add photos (or by using your own tools, importers, etc.), you might have noticed that these new photos don't actually always show up in Synology Photos, even with the indexing service configured to monitor the /photo shared directory.

It seems like Synology Photos's own indexer is not keeping track of file changes/additions, or if it does it doesn't seem to catch newly added files all of the time. In my situation I have noticed photos not showing up in Synology Photos even days after they have been added to the directory.


Screenshot showing some photos in a grid. (actually this is from DSM7, but you get the idea)

Triggering a re-index seems to solve the problem, in that the images do show up eventually after running this. Even though it would be nice if Synology just figured this out by itself –there's built-in functionality for this very purpose in its underlying operating system, after all– it's at least far better than how Photo Station behaved under DSM6. I could never get it to even acknowledge images added outside of its own UI, somehow.

Even though a re-index solves this problem, it is of course less ideal to have to manually trigger this every time you want to browse through your photos. Fortunately there is a way we can use Task Scheduler and the synowebapi command line tool to achieve this.

Setting up a scheduled task

In case you've not used Synology's scheduled task functionality before, it can be found in your Control Panel, under the Services section and is called Task Scheduler. Open this, then click the Create > Scheduled Task > User-defined script.

In the following window, give the task a recognizable name (ie. Re-index Shared Photos), and set the user to root, as that is by default the only user that has permission to use the synowebapi command line tool we'll need to use.

💡
Note: Triggering a re-index for your "personal space" and "shared space" are two separate actions. If you need to do both, you'll have to create two separate tasks. 

Next, under the Schedule section, select the frequency with which you would like this command to run. Depending on your needs you can adjust the schedule to your liking, but keep in mind that this is probably not something you want to run all too often. One index can take quite some time to complete, and your NAS has limited resources.

In my case I set it to Daily, with the Frequency set to Every 12 hours and the Last run time set to 12:00. This way it basically runs a re-index twice daily.

Lastly, under the Task Settings section you can paste the following script in the User-defined script text field, substituting {username} with the username of the user account on your Synology NAS.

💡
2023 Update: It seems like some time after I originally posted my how-to, Synology has changed the required properties of the synowebapi command. I have updated the commands below to reflect this change.

For re-indexing your Shared Space

synowebapi --exec api=SYNO.FotoTeam.Index method=reindex version=1 runner={username} type=basic

For re-indexing your Personal Space

synowebapi --exec api=SYNO.Foto.Index method=reindex version=1  runner={username} type=basic

With that in place, you can hit OK to save your task.

💡
If you for any reason want to manually trigger the "Re-index HEIC files" functionality, you can do this the same way as shown above, substituting type=basic with type=thumbnail.

Knowing what's happening

Synology's software is rather opaque when it comes to showing what's actually happening under the hood, so it might not always be entirely clear when (and what) is happening. It does seem like the "Indexing..." status message does usually eventually show up in Synology Photos' settings panel, although it might take a bit after triggering the script before it does so.

This is something to keep in mind, as this text not showing up right after triggering the command doesn't necessarily mean it didn't work. I'd recommend when you try triggering the task that you wait at least 5 minutes to see if something's happening.

If you want to check what's currently happening via command line, you can run the following command from a SSH session. Note that you need to run this from an account that has sudo access.

sudo synowebapi --exec api=SYNO.Foto.Index method=get version=1 runner=$USER

The results returned may look something like this:

{
   "data" : {
      "basic" : 39151,
      "face_extraction" : 157,
      "geo_coding" : 0,
      "metadata" : 1,
      "metadata_updating" : 0,
      "person_clustering" : 0,
      "thumbnail" : 69658
   },
   "httpd_restart" : false,
   "success" : true
}

The numbers should represent how many photos are being processed in their respective categories (ie. basic for general indexing, face_extraction for facial recognition, et cetera), but keep in mind that this number may initially grow before it shrinks, as it builds up total numbers while at the same time walking through and processing images.

I'd honestly recommend to just turn it on and leave it be, but if you are working on creating some kind of frontend or script where this kind of information is useful, I thought I'd include it here.


-

And that should be it. Actual indexing time varies greatly depending on how many photos and videos you have of course, but from now on images and videos that have been added outside of using Synology's own apps will will start showing up following your defined schedule.

Enjoy!