private Update GetBaseUpdateParticipantStatusesForItemQuery(ExitFromCampaignElement element) { var statusIdToSet = GetParticipantStatusToSet(element.IsCampaignGoal); var update = new Update(UserConnection, CampaignParticipantTableName) .Set("StatusId", Column.Parameter(statusIdToSet)) .Set("StepModifiedOn", Column.Parameter(DateTime.UtcNow)); update.WithHints(new RowLockHint()); return(update); }
private void ActualizeParticipantStatusesForItem(ExitFromCampaignElement element) { if (UseCampaignBatchedQueries) { BatchedUpdateParticipantStatusesForItem(element); } else { UpdateParticipantStatusesForItem(element); } }
private void UpdateParticipantStatusesForItem(ExitFromCampaignElement element) { var update = GetBaseUpdateParticipantStatusesForItemQuery(element); var statusesToUpdate = GetParticipantStatusesToUpdate(element.IsCampaignGoal); update.Where("CampaignId").IsEqual(Column.Parameter(CampaignSchema.EntityId)) .And("CampaignItemId").IsEqual(Column.Parameter(element.UId)) .And("StepCompleted").IsEqual(Column.Const(true)) .And("StatusId").In(Column.Parameters(statusesToUpdate)); update.Execute(); }
private Select GetParticipantIdsToUpdateSelectQuery(ExitFromCampaignElement element) { var statusesToUpdate = GetParticipantStatusesToUpdate(element.IsCampaignGoal); var select = new Select(UserConnection) .Column("Id") .From(CampaignParticipantTableName) .Where("CampaignId").IsEqual(Column.Parameter(CampaignSchema.EntityId)) .And("CampaignItemId").IsEqual(Column.Parameter(element.UId)) .And("StepCompleted").IsEqual(Column.Const(true)) .And("StatusId").In(Column.Parameters(statusesToUpdate)) as Select; select.SpecifyNoLockHints(); return(select); }
private void BatchedUpdateParticipantStatusesForItem(ExitFromCampaignElement element) { var participantsSelect = GetParticipantIdsToUpdateSelectQuery(element); var participantsCollection = participantsSelect .ExecuteEnumerable(r => r.GetColumnValue <Guid>("Id")).ToList(); int participantsCount = participantsCollection.Count; int batchSize = CampaignElementAudienceQueryBatchSize; int processedCount = 0; while (processedCount < participantsCount) { var participantsBatch = participantsCollection.Skip(processedCount).Take(batchSize); var updateQuery = GetBaseUpdateParticipantStatusesForItemQuery(element); updateQuery.Where("Id").In(Column.Parameters(participantsBatch)); updateQuery.Execute(); processedCount += batchSize; Task.Delay(10).Wait(); } }
/// <summary> /// Constructor for <see cref="ExitFromCampaignElement"/>. /// </summary> /// <param name="source">Instance of <see cref="ExitFromCampaignElement"/>.</param> /// <param name="dictToRebind">Dictionary to rebind schema elements' ids.</param> /// <param name="parentSchema">Parent campaign schema.</param> public ExitFromCampaignElement(ExitFromCampaignElement source, Dictionary <Guid, Guid> dictToRebind, Core.Campaign.CampaignSchema parentSchema) : base(source, dictToRebind, parentSchema) { IsCampaignGoal = source.IsCampaignGoal; }
/// <summary> /// Constructor for <see cref="ExitFromCampaignElement"/>. /// </summary> /// <param name="source">Instance of <see cref="ExitFromCampaignElement"/>.</param> public ExitFromCampaignElement(ExitFromCampaignElement source) : this(source, null, null) { }