Handle legacy attempts during statistics backfill

This commit is contained in:
hz
2026-07-13 10:25:44 -05:00
parent 93154d5925
commit 361847cae2
@@ -154,6 +154,10 @@ public sealed class AnswerStatisticsStore
{ {
return false; return false;
} }
catch (MongoCommandException exception) when (exception.Code == 11000)
{
return false;
}
} }
public async Task MarkBackfillCompleteAsync(string owner) public async Task MarkBackfillCompleteAsync(string owner)
@@ -203,7 +207,13 @@ public sealed class AnswerStatisticsStore
new BsonDocument("$match", match), new BsonDocument("$match", match),
new BsonDocument("$group", new BsonDocument new BsonDocument("$group", new BsonDocument
{ {
{ "_id", new BsonDocument { { "q", "$QuestionExternalId" }, { "b", "$CounterBucket" }, { "c", "$ChoiceId" } } }, { "_id", new BsonDocument
{
{ "q", "$QuestionExternalId" },
{ "b", new BsonDocument("$ifNull", new BsonArray { "$CounterBucket", 0 }) },
{ "c", "$ChoiceId" }
}
},
{ "count", new BsonDocument("$sum", 1) } { "count", new BsonDocument("$sum", 1) }
}) })
}; };
@@ -214,7 +224,13 @@ public sealed class AnswerStatisticsStore
new BsonDocument("$unwind", "$PresentedChoiceIds"), new BsonDocument("$unwind", "$PresentedChoiceIds"),
new BsonDocument("$group", new BsonDocument new BsonDocument("$group", new BsonDocument
{ {
{ "_id", new BsonDocument { { "q", "$QuestionExternalId" }, { "b", "$CounterBucket" }, { "c", "$PresentedChoiceIds" } } }, { "_id", new BsonDocument
{
{ "q", "$QuestionExternalId" },
{ "b", new BsonDocument("$ifNull", new BsonArray { "$CounterBucket", 0 }) },
{ "c", "$PresentedChoiceIds" }
}
},
{ "count", new BsonDocument("$sum", 1) } { "count", new BsonDocument("$sum", 1) }
}) })
}; };
@@ -231,7 +247,12 @@ public sealed class AnswerStatisticsStore
new BsonDocument("$match", legacyMatch), new BsonDocument("$match", legacyMatch),
new BsonDocument("$group", new BsonDocument new BsonDocument("$group", new BsonDocument
{ {
{ "_id", new BsonDocument { { "q", "$QuestionExternalId" }, { "b", "$CounterBucket" } } }, { "_id", new BsonDocument
{
{ "q", "$QuestionExternalId" },
{ "b", new BsonDocument("$ifNull", new BsonArray { "$CounterBucket", 0 }) }
}
},
{ "count", new BsonDocument("$sum", 1) } { "count", new BsonDocument("$sum", 1) }
}) })
}; };