Skip to content

Commit

Permalink
Add developer settings and a synchronization limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rcloran committed May 2, 2023
1 parent e7c6aa0 commit 5d028dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lr-inaturalist-publish.lrdevplugin/DevSettings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local LrFileUtils = import("LrFileUtils")
local LrPathUtils = import("LrPathUtils")

local JSON = require("JSON")

local home = LrPathUtils.getStandardFilePath("home")
local f = LrPathUtils.child(home, ".lr-inaturalist-publish.json")

if not LrFileUtils.isReadable(f) then
return {}
end

local v = JSON:decode(LrFileUtils.readFile(f))

if type(v) ~= "table" then
return {}
end

return v
4 changes: 2 additions & 2 deletions lr-inaturalist-publish.lrdevplugin/INaturalistAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ end
-- into one table.
-- Overrides per_page, order_by, order, id_above, id_below in the search;
-- results are always ordered descending by id.
function INaturalistAPI:listObservationsWithPagination(search, progress)
function INaturalistAPI:listObservationsWithPagination(search, progress, limit)
local results, resultsRemain = {}, true

search = shallowCopy(search)
Expand All @@ -245,7 +245,7 @@ function INaturalistAPI:listObservationsWithPagination(search, progress)
search.id_above = nil
search.id_below = nil

while resultsRemain do
while resultsRemain and (not limit or #results < limit) do
if progress:isCanceled() then
error({ code = "canceled", message = "Canceled by user" })
end
Expand Down
4 changes: 3 additions & 1 deletion lr-inaturalist-publish.lrdevplugin/SyncObservations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local LrFunctionContext = import("LrFunctionContext")
local LrPasswords = import("LrPasswords")
local LrProgressScope = import("LrProgressScope")

local DevSettings = require("DevSettings")
local INaturalistAPI = require("INaturalistAPI")
local INaturalistMetadata = require("INaturalistMetadata")

Expand Down Expand Up @@ -505,7 +506,8 @@ local function sync(functionContext, settings, progress, api, lastSync)
-- caption seems to do what I actually want.
progress:setCaption(caption)
end
local observations = api:listObservationsWithPagination(query, dlProgress)

local observations = api:listObservationsWithPagination(query, dlProgress, DevSettings.syncLimit)

-- Now apply downloaded data to the catalog
local syncProgress = LrProgressScope({
Expand Down

0 comments on commit 5d028dd

Please sign in to comment.