Bulk update of cards

Overview

Ordinarily the Mercury Communication service receives individual data update requests, such as adding or deleting a card assignment, by monitoring ObjectMod events on the MQTT events stream. This approach keeps the cards collection in the Keep database in sync with the cards collection on the Mercury Controller in real time.

However this approach is less efficient when a large number of card assignment changes are required, such as extending the expiration of a set of cards, or disabling a set of cards. Therefore, two API wrapper methods are available to improve the performance of bulk card updates, to be used in specific cases: Extending Expiration dates of cards, and disabling active cards.

Extend Card Expiration

To extend the expiration date of a set of cards use the ExtendCardExpiry method. This method will search the supplied instance for active cards with an expiration date between the two dates provide in the method call ExpiresAfter and ExpiresBefore. The Card will be updated with the new ExpiresOn on value that is supplied in the method call.

As there may be thousands of cards to update this method works in batch sizes of 500 cards at a time. The method returns the number of cards processed. Call this method repeatedly, but not in parallel, until the number of cards updated is zero. As a convenience passing trialrun of true will return the total number of cards expected to be processed, without processing any of the cards. Use this value as an estimate of the total work to be done, for example to set the upper limit of a progress indicator in a User Interface.


// extend active cards by 1 year that are set to expire in the next 60 days
var root = await client.GetCurrentInstanceAsync();

var cardsToProcess = await client.ExtendCardExpiry(root, DateTime.UtcNow.AddDays(60),DateTime.UtcNow, DateTime.UtcNow.AddYears(1),true);
var limit=cardsToProcess.CardsUpdated;
while(limit >0)
{
    var response = await client.ExtendCardExpiry(root, DateTime.UtcNow.AddDays(60),DateTime.UtcNow, DateTime.UtcNow.AddYears(1),false);
    limit = response.CardUpdated;
}

Disable Active Cards

Similar to ExtendCardExpiry the method DisableActiveCardsAsync will disable active cards in bulk. In this case the method takes a MongoDb search string to select people to be disabled. The typical use case for this feature is part of a COVID screening process, where in the cards are disabled at the end of the shift, and only enabled when the person has completed a COVID screening process the next day.

For example, consider the scenario of all people, except those tagged management must complete the screening form. The search string in this case would be:

{"_t":"Person","Tags":{"$ne":"management"}}

This method also works in batch sizes of 500 cards at a time. Therefore the same looping structure and trialrun behavior as the ExtendCardExpiry should be applied.

var root = await client.GetCurrentInstanceAsync();
var query = "{'_t':'Person','Tags':{'$ne':'management'}}";
var cardsToProcess = await client.DisableActiveCardsAsync(root, query,true); // call with trialrun=true to get the total number of people to process
var limit=cardsToProcess.CardsUpdated;
while(limit >0)
{
    var response = await client.DisableActiveCardsAsync(root,query,false);
    limit = response.CardUpdated;
}