• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

SDK - Collection are not updated in the application view

New Here ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

Hi,

 

I'm experiencing an issue since the LR version 11.0 update where the SDK commands concerning collections are not taking effect on the application view. For example, if I'm trying to run the following code:

 

local LrTasks = import 'LrTasks'
local LrApplication = import 'LrApplication'
LrTasks.startAsyncTask( function ()
local catalog = LrApplication.activeCatalog()
local message = catalog:withWriteAccessDo("Managing collections", function ()
local collectionSet = catalog:createCollectionSet("Test set", nil, true)
local collection1 = catalog:createCollection("Test collection1", collectionSet, true)
collection1:addPhotos(catalog:getAllPhotos())
local collection2 = catalog:createCollection("Test collection2", collectionSet, true)
collection2:addPhotos(catalog:getAllPhotos())
end)
end)
 
The collections in App view may sometime not be updated. Sometime it is only partially updated (not all images appear in the collection). I know from the output in the code that the commands were executed successfully. Moreover, if I'm restarting LR, the collections are indeed updated.
*I'm running on macOS and, as I understand, this issue does not occur on Windows.
 
Are you familiar with the issue? Is there anything else I should add to the code?
 
App version - LrC 11.1
OS - macOS 11.6.2
 
 
TOPICS
SDK

Views

114

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2022 Jan 09, 2022

Copy link to clipboard

Copied

How many photos are being added to the collections?  When I run that script on a 1000-photo catalog, it completes nearly instantaneously, and the created collections appear fully populated. But when I run it ona catalog with 36K photos, it takes many minutes to complete, and the collections didn't appear in the Collections panel until a couple minutes after starting the script.

 

collection:addPhotos() has long had an n-squared performance bug that's causing this misbehavior:

https://community.adobe.com/t5/lightroom-classic-discussions/creating-large-collections-via-the-sdk/...

 

So try re-running your test, and use Activity Monitor to observe the CPU time of the Lightroom Classic process while running the script.  After the CPU utilization drops to a few percent, do the collections now appear in the Collections panel fully populated?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Thanks for replying.

I've managed to resolve the issue (although indirectly).

I believe the issue is not related to run time but rather to the LR GUI refresh "cycle".

LR did not refresh to GUI after adding the photos.

In order to "trigger" the refresh I've splitted the creation of the collection and the insertion of the photos into 2 separate write access commands. The following code works:

 

local LrTasks = import 'LrTasks'
local LrApplication = import 'LrApplication'
LrTasks.startAsyncTask( function ()
local catalog = LrApplication.activeCatalog()
local collectionSet = nil
local collection1 = nil
local collection2 = nil
local message1 = catalog:withWriteAccessDo("Creating collections", function ()
collectionSet = catalog:createCollectionSet("Test set", nil, true)
collection1 = catalog:createCollection("Test collection1", collectionSet, true)
collection2 = catalog:createCollection("Test collection2", collectionSet, true)
end)
local message2 = catalog:withWriteAccessDo("adding photos to collections", function ()
collection1:addPhotos(catalog:getAllPhotos())
collection2:addPhotos(catalog:getAllPhotos())
end)
end)
 
 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

LATEST

Glad you found a workaround.   Reviewing the code in some of my plugins, I see that I've done the same thing, but I had written comments saying that trying to add photos to a newly created collection inside a singlewithWriteAccessDo() would fail with an error (the collection wouldn't appear to be created until the withWriteAccessDo() exited).  But not all my plugins split up creation and adding.  So this, and the n-squared performance bug, is clearly something fragile in LR internals that interacts badly with refreshing the UI.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines