public ExecuteCounterBatchCommand(DocumentDatabase database, CounterBatch counterBatch) { _database = database; _dictionary = new Dictionary <string, List <CounterOperation> >(); _replyWithAllNodesValues = counterBatch?.ReplyWithAllNodesValues ?? false; _fromEtl = counterBatch?.FromEtl ?? false; CountersDetail = new CountersDetail { Counters = new List <CounterDetail>() }; if (counterBatch == null) { return; } foreach (var docOps in counterBatch.Documents) { foreach (var operation in docOps.Operations) { HasWrites |= operation.Type != CounterOperationType.Get && operation.Type != CounterOperationType.None; Add(docOps.DocumentId, operation); } } }
public void CanGetCounterWhichDoesntExist() { using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { session.Store(new User { Name = "Raven" }, "users/1-A"); session.SaveChanges(); } var longCounterName = new string('a', 5); var documentCountersOperation = new DocumentCountersOperation { DocumentId = "users/1-A", Operations = new List <CounterOperation>() { new CounterOperation() { CounterName = longCounterName, Type = CounterOperationType.Increment, Delta = 5 } } }; var counterBatch = new CounterBatch { Documents = new List <DocumentCountersOperation>() { documentCountersOperation } }; store.Operations.Send(new CounterBatchOperation(counterBatch)); using (var session = store.OpenSession()) { var dic = session.CountersFor("users/1-A") .Get(new string[] { longCounterName, "no_such" }); Assert.Equal(dic.Count, 1); } } }
public ExecuteCounterBatchCommand(DocumentDatabase database, CounterBatch counterBatch) { _database = database; _list = new List <CounterOperation>(); _replyWithAllNodesValues = counterBatch?.ReplyWithAllNodesValues ?? false; _fromEtl = counterBatch?.FromEtl ?? false; if (counterBatch == null) { return; } foreach (var docOps in counterBatch.Documents) { foreach (var operation in docOps.Operations) { HasWrites |= operation.Type != CounterOperationType.Get && operation.Type != CounterOperationType.None; operation.DocumentId = docOps.DocumentId; _list.Add(operation); } } }
public void BatchWithDifferentTypesOfOperations() { using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { session.Store(new User { Name = "Aviv1" }, "users/1-A"); session.Store(new User { Name = "Aviv2" }, "users/2-A"); session.Store(new User { Name = "Aviv3" }, "users/3-A"); session.SaveChanges(); } store.Operations.Send(new CounterBatchOperation(new CounterBatch { Documents = new List <DocumentCountersOperation> { new DocumentCountersOperation { DocumentId = "users/1-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "likes", Delta = 10 }, new CounterOperation { Type = CounterOperationType.Increment, CounterName = "dislikes", Delta = 20 } } }, new DocumentCountersOperation { DocumentId = "users/2-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "rank", Delta = 30 } } }, new DocumentCountersOperation { DocumentId = "users/3-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "score", Delta = 40 } } } } })); var dic = store.Operations .Send(new GetCountersOperation("users/1-A", new[] { "likes", "dislikes" })) .Counters .ToDictionary(c => c.CounterName, c => c.TotalValue); Assert.Equal(2, dic.Count); Assert.Equal(10, dic["likes"]); Assert.Equal(20, dic["dislikes"]); var value = store.Operations .Send(new GetCountersOperation("users/2-A", new [] { "rank" })) .Counters[0]?.TotalValue; Assert.Equal(30, value); value = store.Operations .Send(new GetCountersOperation("users/3-A", new[] { "score" })) .Counters[0]?.TotalValue; Assert.Equal(40, value); var batch = new CounterBatch { Documents = new List <DocumentCountersOperation> { new DocumentCountersOperation { DocumentId = "users/1-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "likes", Delta = 100 }, new CounterOperation { Type = CounterOperationType.Delete, CounterName = "dislikes" } } }, new DocumentCountersOperation { DocumentId = "users/2-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "rank", Delta = 200 }, new CounterOperation { //create new counter Type = CounterOperationType.Increment, CounterName = "downloads", Delta = 300 } } }, new DocumentCountersOperation { DocumentId = "users/3-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Delete, CounterName = "score" } } } } }; var countersDetail = store.Operations.Send(new CounterBatchOperation(batch)); Assert.Equal(3, countersDetail.Counters.Count); Assert.Equal("users/1-A", countersDetail.Counters[0].DocumentId); Assert.Equal("likes", countersDetail.Counters[0].CounterName); Assert.Equal(110, countersDetail.Counters[0].TotalValue); Assert.Equal("users/2-A", countersDetail.Counters[1].DocumentId); Assert.Equal("rank", countersDetail.Counters[1].CounterName); Assert.Equal(230, countersDetail.Counters[1].TotalValue); Assert.Equal("users/2-A", countersDetail.Counters[2].DocumentId); Assert.Equal("downloads", countersDetail.Counters[2].CounterName); Assert.Equal(300, countersDetail.Counters[2].TotalValue); Assert.Equal(0, store.Operations.Send(new GetCountersOperation("users/1-A", new [] { "dislikes" })).Counters.Count); Assert.Equal(0, store.Operations.Send(new GetCountersOperation("users/3-A", new[] { "score" })).Counters.Count); } }
public void MultiSetAndGetViaBatch() { using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { session.Store(new User { Name = "Aviv" }, "users/1-A"); session.Store(new User { Name = "Aviv2" }, "users/2-A"); session.SaveChanges(); } var setBatch = new CounterBatch { Documents = new List <DocumentCountersOperation> { new DocumentCountersOperation { DocumentId = "users/1-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "likes", Delta = 5 }, new CounterOperation { Type = CounterOperationType.Increment, CounterName = "dislikes", Delta = 10 } } }, new DocumentCountersOperation { DocumentId = "users/2-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Increment, CounterName = "rank", Delta = 20 } } } } }; store.Operations.Send(new CounterBatchOperation(setBatch)); var getBatch = new CounterBatch { Documents = new List <DocumentCountersOperation> { new DocumentCountersOperation { DocumentId = "users/1-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Get, CounterName = "likes" }, new CounterOperation { Type = CounterOperationType.Get, CounterName = "dislikes" } } }, new DocumentCountersOperation { DocumentId = "users/2-A", Operations = new List <CounterOperation> { new CounterOperation { Type = CounterOperationType.Get, CounterName = "rank" } } } } }; var countersDetail = store.Operations.Send(new CounterBatchOperation(getBatch)); Assert.Equal(3, countersDetail.Counters.Count); Assert.Equal("likes", countersDetail.Counters[0].CounterName); Assert.Equal("users/1-A", countersDetail.Counters[0].DocumentId); Assert.Equal(5, countersDetail.Counters[0].TotalValue); Assert.Equal("dislikes", countersDetail.Counters[1].CounterName); Assert.Equal("users/1-A", countersDetail.Counters[1].DocumentId); Assert.Equal(10, countersDetail.Counters[1].TotalValue); Assert.Equal("rank", countersDetail.Counters[2].CounterName); Assert.Equal("users/2-A", countersDetail.Counters[2].DocumentId); Assert.Equal(20, countersDetail.Counters[2].TotalValue); } }
public CounterBatchOperation(CounterBatch counterBatch) #endregion { }
public async Task Post(CreatePerks request) { var perks = new List <Perk>() { new Perk { Id = "Perk/vegan", Name = "Веганство", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/vegan.png", KeyWords = new List <string> { "сыроед", "веган", "вегетариан", } }, new Perk { Id = "Perk/eatmeet", Name = "Мясоедство", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/eatmeet.png", KeyWords = new List <string> { "мясо", "мясоед", } }, new Perk { Id = "Perk/antivaccination", Name = "Против прививок", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/antivaccination.png", KeyWords = new List <string> { "прививка", "вакцина", "грип", "covid", "ковид", } }, new Perk { Id = "Perk/vaccination", Name = "За прививки", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/vaccination.png", KeyWords = new List <string> { "прививка", "вакцина", "грип", "covid", "ковид", } }, new Perk { Id = "Perk/krymru", Name = "Крым - РФ", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/krymru.png", KeyWords = new List <string> { "крым", } }, new Perk { Id = "Perk/krymua", Name = "Крым - Украина", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/krymua.png", KeyWords = new List <string> { "крым", } }, new Perk { Id = "Perk/aborting", Name = "За аборты", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/aborting.png", KeyWords = new List <string> { "аборт", } }, new Perk { Id = "Perk/antiaborting", Name = "Против абортов", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/antiaborting.png", KeyWords = new List <string> { "аборт", } }, new Perk { Id = "Perk/traditionsex", Name = "Традиционные половые отношения", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/traditionsex.png", KeyWords = new List <string> { "семья", "дети", "ребенок", "любов", } }, new Perk { Id = "Perk/nontraditionsex", Name = "Не традиционные половые отношения", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/nontraditionsex.png", KeyWords = new List <string> { "геи", "лесби", "лгбт", "транссексуал", "прайд", "любов", } }, new Perk { Id = "Perk/filthylanguage", Name = "Мат", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/filthylanguage.png", KeyWords = new List <string> { "редиска", "f**k", } }, new Perk { Id = "Perk/adult", Name = "18+", ImagePath = "https://github.com/Kibnet/Axiometr.Server/raw/master/resources/adult.png", KeyWords = new List <string> { "порно", "секс", "убить", "кровь", } } }; foreach (var perk in perks) { await RavenSession.StoreAsync(perk); } var medusa = new PageProfile { Address = "https://meduza.io/" }; var wonderzine = new PageProfile { Address = "https://www.wonderzine.com/" }; var profiles = new List <PageProfile> { medusa, wonderzine, }; foreach (var profile in profiles) { await RavenSession.StoreAsync(profile); } await RavenSession.SaveChangesAsync(); DocumentCountersOperation operation1 = new DocumentCountersOperation { DocumentId = RavenSession.Advanced.GetDocumentId(medusa), Operations = new List <CounterOperation> { new CounterOperation() { CounterName = "krymua", Delta = 10, Type = CounterOperationType.Increment, }, } }; CounterBatch counterBatch = new CounterBatch(); counterBatch.Documents.Add(operation1); var counteBatch = new CounterBatchOperation(counterBatch); RavenSession.Advanced.DocumentStore.Operations.Send(counteBatch); }