Multimap with load doesn't keep up to date until a new related doc is added or deleted.

26 views
Skip to first unread message

Wyatt Webb

unread,
Jul 28, 2014, 12:29:36 PM7/28/14
to rav...@googlegroups.com
We have a MutiMapIndexCreationTask. There is an internal load that pulls in related data. We know that is not best practice, and the data should be denormalized if possible, but that's not an option at this moment. When the index is defined it appears to work correctly, until one of the related docs is updated. At that point the related document gets out of sync and the index is not updated. This continues to happen until an additional related doc is added to the top level doc as a relationship, at this point everything works as expected.

Here is the Index Definition. The offending property is "LastFirstDisplayName" on a contact.


AddMap<Client>(clients =>
                from client in clients
                select new
                {
                    ClientId = client.Id_ForIndexing,
                    ProfileId = (Guid?)null,
                    ProfileName = (string)null,
                    ProfileReqNbr = Int64.MaxValue,
                    Contacts = new object[] { }
                }
            );

            AddMap<Client>(
                clients =>
                    from client in clients
                    from clientRelationship in client.Contacts
                    let clientContact = LoadDocument<Contact>("Contacts/" + clientRelationship.ContactId)
                    select new
                    {
                        ClientId = client.Id_ForIndexing,
                        ProfileId = (Guid?)null,
                        ProfileName = (string)null,
                        ProfileReqNbr = 0L,
                        Contacts = clientContact == null
                            ? new object[] { }
                            : new[]
                            {
                                new
                                {
                                    ContactId = clientContact.Id_ForIndexing,
                                    ContactName = clientContact.LastFirstDisplayName,
                                    IsReportRecipient = clientRelationship.IsReportRecipient,
                                    IsInvoiceRecipient = clientRelationship.IsInvoiceRecipient
                                }
                            }
                    }
                );

            AddMap<Client>(clients =>
                from client in clients
                from profile in client.Profiles
                select new
                {
                    ClientId = client.Id_ForIndexing,
                    ProfileId = profile.Id,
                    ProfileName = String.Format("{0} {1}", profile.ReqNbr, profile.Name),
                    ProfileReqNbr = profile.ReqNbr,
                    Contacts = new object[] { }
                }
            );

            AddMap<Client>(
                clients =>
                    from client in clients
                    from profile in client.Profiles
                    from profileRelationship in profile.Contacts
                    let profileContact = LoadDocument<Contact>("Contacts/" + profileRelationship.ContactId)
                    select new
                    {
                        ClientId = client.Id_ForIndexing,
                        ProfileId = profile.Id,
                        ProfileName = String.Format("{0} {1}", profile.ReqNbr, profile.Name),
                        ProfileReqNbr = profile.ReqNbr,
                        Contacts = profileContact == null
                            ? new object[] { }
                            : new[]
                            {
                                new
                                {
                                    ContactId = profileContact.Id_ForIndexing,
                                    ContactName = profileContact.LastFirstDisplayName,
                                    IsReportRecipient = profileRelationship.IsReportRecipient,
                                    IsInvoiceRecipient = profileRelationship.IsInvoiceRecipient
                                }
                            }
                    }
                );

            Reduce = results =>
                from result in results
                group result by new
                {
                    result.ClientId,
                    result.ProfileId
                } into grouped
                select new ClientContactTreeResult
                {
                    ClientId = grouped.Key.ClientId,
                    ProfileId = grouped.Key.ProfileId,
                    ProfileName = grouped.Select(x => x.ProfileName).First(),
                    ProfileReqNbr = grouped.Select(x => x.ProfileReqNbr).First(),
                    Contacts = grouped
                        .SelectMany(x => x.Contacts)
                        .OrderBy(x => x.ContactName)
                        .ToArray()
                };

            Index(x => x.ProfileReqNbr, FieldIndexing.Default);

            Sort(x => x.ProfileReqNbr, SortOptions.Long);

Oren Eini (Ayende Rahien)

unread,
Jul 28, 2014, 1:01:42 PM7/28/14
to ravendb

What build are you using?

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wyatt Webb

unread,
Jul 28, 2014, 1:19:01 PM7/28/14
to rav...@googlegroups.com
2874

Oren Eini (Ayende Rahien)

unread,
Jul 29, 2014, 2:50:59 AM7/29/14
to ravendb
Can you try with 2910? 
If this is still an issue, we'll like to see a repro.



Oren Eini

CEO


Mobile: + 972-52-548-6969

Office:  + 972-4-622-7811

Fax:      + 972-153-4622-7811



Wyatt Webb

unread,
Jul 29, 2014, 9:05:39 AM7/29/14
to rav...@googlegroups.com
2910 Seems to resolve the issue. I see in the change log that there have been significant changes between the version we were using and 2910. Do you have any recommendation as to what we should regression test as part of this change?

-Wyatt

Oren Eini (Ayende Rahien)

unread,
Jul 30, 2014, 3:54:24 AM7/30/14
to ravendb
The reason that I suggested the upgrade is that we fixed a few things that could cause it, if this resolve the issue, than that is is.
Reply all
Reply to author
Forward
0 new messages