Forum Discussion
Keyser_Soze
2 years agoContributor
Edit member properties in Bulk
I need to update the properties (Constraints/Texts) of 20.000 UD members based on transformation rules.
The script runs in 10 seconds, but once I add the 'SaveMemberInfo' method it surpasses 2h .....
- 2 years ago
Hi Keyser_Soze !
Updating members can be risky - but you already know that.
Regarding the time it takes, it is normal as it is a Brapi and it will do 20 000 connections to the database.
Now, for testing purposes you could test with Parralle for Each and something like this :Imports System.Threading.Tasks ' Assuming ListofU1Stores is a list or collection that supports parallel iteration Parallel.ForEach(ListofU1Stores, Sub(oStore) ' Assume these API calls are thread-safe and can be called concurrently Dim objWritableMember As WritableMember = BRApi.Finance.Members.ReadWritableMemberNoCache(si, DimType.UD1.Id, oStore.Member.Name) Dim objVaryingMemberProperties As VaryingMemberProperties = BRApi.Finance.Members.ReadMemberPropertiesNoCache(si, DimType.UD1.Id, oStore.Member.Name) Dim StoreUDVMInfo As UDVMProperties = objVaryingMemberProperties.GetUDProperties() StoreUDVMInfo.Text1.SetStoredValue(ScenarioType.Unknown.Id, DimConstants.Unknown, text1ToAssign) StoreUDVMInfo.Text2.SetStoredValue(ScenarioType.Unknown.Id, DimConstants.Unknown, text2ToAssign) BRApi.Finance.MemberAdmin.SaveMemberInfo(si, True, objWritableMember, True, objVaryingMemberProperties, False, Nothing, TriStateBool.FalseValue) End Sub)I am not an expert of the drawbacks of parallel for each.
Cheers
NicolasArgente
2 years agoValued Contributor
Hi Keyser_Soze !
Updating members can be risky - but you already know that.
Regarding the time it takes, it is normal as it is a Brapi and it will do 20 000 connections to the database.
Now, for testing purposes you could test with Parralle for Each and something like this :
Imports System.Threading.Tasks
' Assuming ListofU1Stores is a list or collection that supports parallel iteration
Parallel.ForEach(ListofU1Stores, Sub(oStore)
' Assume these API calls are thread-safe and can be called concurrently
Dim objWritableMember As WritableMember = BRApi.Finance.Members.ReadWritableMemberNoCache(si, DimType.UD1.Id, oStore.Member.Name)
Dim objVaryingMemberProperties As VaryingMemberProperties = BRApi.Finance.Members.ReadMemberPropertiesNoCache(si, DimType.UD1.Id, oStore.Member.Name)
Dim StoreUDVMInfo As UDVMProperties = objVaryingMemberProperties.GetUDProperties()
StoreUDVMInfo.Text1.SetStoredValue(ScenarioType.Unknown.Id, DimConstants.Unknown, text1ToAssign)
StoreUDVMInfo.Text2.SetStoredValue(ScenarioType.Unknown.Id, DimConstants.Unknown, text2ToAssign)
BRApi.Finance.MemberAdmin.SaveMemberInfo(si, True, objWritableMember, True, objVaryingMemberProperties, False, Nothing, TriStateBool.FalseValue)
End Sub)
I am not an expert of the drawbacks of parallel for each.
Cheers
RobbSalzmann
2 years agoValued Contributor II
NicolasArgente consider adding ParallelOptions and setting the degreesOfParallelism to 1 less than Environment.ProcessorCount to prevent monopolizing the CPU.
Related Content
- 8 months ago
- 2 years ago