Found a way to access only the images tagged with the old tag instead of searching through all the images in the database. This results in a huge decrease in execution speed, depending on the size of the database.
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
--[[
|
||||||
|
Copyright (c) 2016 Sebastian Witt <se.witt@gmx.net>
|
||||||
|
Copyright (c) 2018 Bill Ferguson <wpferguson@gmail.com>
|
||||||
|
]]
|
||||||
--[[
|
--[[
|
||||||
Rename tags
|
Rename tags
|
||||||
|
|
||||||
@@ -18,6 +22,10 @@ USAGE
|
|||||||
LICENSE
|
LICENSE
|
||||||
GPLv2
|
GPLv2
|
||||||
|
|
||||||
|
Changes
|
||||||
|
* 20180912 - Did an RTFM and read a bug (12277, thanks Christian G) that showed
|
||||||
|
a way to get the images containing the old tag one by one instead of searching
|
||||||
|
the entire database. Changed rename_tags() function to use this method.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local darktable = require "darktable"
|
local darktable = require "darktable"
|
||||||
@@ -27,8 +35,13 @@ local debug = require "darktable.debug"
|
|||||||
local old_tag = darktable.new_widget("entry") { tooltip = "Enter old tag" }
|
local old_tag = darktable.new_widget("entry") { tooltip = "Enter old tag" }
|
||||||
local new_tag = darktable.new_widget("entry") { tooltip = "Enter new tag" }
|
local new_tag = darktable.new_widget("entry") { tooltip = "Enter new tag" }
|
||||||
|
|
||||||
|
local function rename_reset()
|
||||||
|
old_tag.text = ''
|
||||||
|
new_tag.text = ''
|
||||||
|
end
|
||||||
|
|
||||||
-- This function does the renaming
|
-- This function does the renaming
|
||||||
local function rename_tags(widget)
|
local function rename_tags()
|
||||||
-- If entries are empty, return
|
-- If entries are empty, return
|
||||||
if old_tag.text == '' then
|
if old_tag.text == '' then
|
||||||
darktable.print ("Old tag can't be empty")
|
darktable.print ("Old tag can't be empty")
|
||||||
@@ -39,7 +52,7 @@ local function rename_tags(widget)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local Count = 0
|
local count = 0
|
||||||
|
|
||||||
-- Check if old tag exists
|
-- Check if old tag exists
|
||||||
local ot = darktable.tags.find (old_tag.text)
|
local ot = darktable.tags.find (old_tag.text)
|
||||||
@@ -58,29 +71,28 @@ local function rename_tags(widget)
|
|||||||
-- Create if it does not exists
|
-- Create if it does not exists
|
||||||
local nt = darktable.tags.create (new_tag.text)
|
local nt = darktable.tags.create (new_tag.text)
|
||||||
|
|
||||||
-- Search images for old tag
|
-- Get number of images for old tag
|
||||||
dbcount = #darktable.database
|
local dbcount = #ot
|
||||||
for i,image in ipairs(darktable.database) do
|
|
||||||
|
-- loop through the images containing the old tag, and attach the new tag
|
||||||
|
for i=1, #ot do
|
||||||
-- Update progress bar
|
-- Update progress bar
|
||||||
job.percent = i / dbcount
|
job.percent = i / dbcount
|
||||||
|
ot[i]:attach_tag(nt)
|
||||||
local tags = image:get_tags ()
|
count = count + 1
|
||||||
for _,t in ipairs (tags) do
|
|
||||||
if t.name == old_tag.text then
|
|
||||||
-- Found it, attach new tag
|
|
||||||
image:attach_tag (nt)
|
|
||||||
Count = Count + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Delete old tag, this removes it from all images
|
-- Delete old tag, this removes it from all images
|
||||||
darktable.tags.delete (ot)
|
darktable.tags.delete (ot)
|
||||||
|
|
||||||
job.valid = false
|
job.valid = false
|
||||||
darktable.print ("Renamed tags for " .. Count .. " images")
|
darktable.print ("Renamed tags for " .. count .. " images")
|
||||||
old_tag.editable = true
|
old_tag.editable = true
|
||||||
new_tag.editable = true
|
new_tag.editable = true
|
||||||
|
|
||||||
|
-- reset the gui fields
|
||||||
|
|
||||||
|
rename_reset()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- GUI
|
-- GUI
|
||||||
@@ -96,11 +108,6 @@ local new_widget = darktable.new_widget ("box") {
|
|||||||
new_tag
|
new_tag
|
||||||
}
|
}
|
||||||
|
|
||||||
local function rename_reset(widget)
|
|
||||||
old_tag.text = ''
|
|
||||||
new_tag.text = ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local rename_widget = darktable.new_widget ("box") {
|
local rename_widget = darktable.new_widget ("box") {
|
||||||
orientation = "vertical",
|
orientation = "vertical",
|
||||||
reset_callback = rename_reset,
|
reset_callback = rename_reset,
|
||||||
|
|||||||
Reference in New Issue
Block a user