Module:LuaTemplateBlueprint: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 1,017: Line 1,017:
     end
     end
      
      
     -- Process country and region properties with the new batch-friendly approach
     -- Process country and region properties with early deduplication
     -- if a country field exists and country is not in skipProperties
     -- if a country field exists and country is not in skipProperties
     if args.country and args.country ~= '' and not skipProperties["Has country"] then
     if args.country and args.country ~= '' and not skipProperties["Has country"] then
Line 1,030: Line 1,030:
         )
         )
          
          
         -- Merge country properties into allProperties with deduplication
         -- Process country properties through deduplication
         if countryProperties and next(countryProperties) then
         if countryProperties and next(countryProperties) then
             for property, values in pairs(countryProperties) do
             for property, values in pairs(countryProperties) do
                 -- Skip if explicitly marked to skip (double-check)
                 -- Skip if explicitly marked to skip
                 if not skipProperties[property] then
                 if not skipProperties[property] then
                     if not allProperties[property] then
                     if type(values) == "table" then
                         -- Property doesn't exist yet, add directly
                         -- Process each value through deduplication
                         allProperties[property] = values
                        for _, value in ipairs(values) do
                            deduplicateProperty(collector, property, value)
                         end
                     else
                     else
                         -- Property already exists, merge with existing values
                         -- Single value
                         if type(allProperties[property]) ~= "table" then
                         deduplicateProperty(collector, property, values)
                            -- Convert existing value to array
                            allProperties[property] = {allProperties[property]}
                        end
                       
                        -- Add unique values
                        local seenValues = {}
                        for _, v in ipairs(allProperties[property]) do
                            seenValues[v] = true
                        end
                       
                        for _, v in ipairs(values) do
                            if not seenValues[v] then
                                seenValues[v] = true
                                table.insert(allProperties[property], v)
                            end
                        end
                     end
                     end
                 end
                 end