4 Replies Latest reply on Nov 9, 2011 4:52 AM by MBanchuzhnyy

    How to know number of Notification History Records

    MBanchuzhnyy

      Hello everybody,

       

       

       

      I'm writing notification web service which allows to retrieve notification history. The question is, is it possible to know number of history records without execution time consuming statements like this: 

       

       

       

      // Step 1 - get all notification objects

       

      ANNotificationList notificationList = new ANNotificationList(AFNotification.FindNotifications( AFDatabase, "", AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 10000));

       

       

       

      // Step 2 - get all history records 

      List<ANNotificationInstances> notificationInstances = notificationList.GetInstances(startTime, endTime));

       

       

       

      // Step 3 - analize histiory records one by one 

      foreach (ANNotificationInstances instances in notificationInstances)

      {

      ...

      }

      Thank you.

       

       

       

       

      Step 2  takes a lot of time in case there are a lot of records in the history, but I need to know number of records before going through all of them (the purpose of that is time assessment). In other words, is there in API capability to get just number of history records for each notification object. Maybe there is some static information class which I cannot find?

       

       

       

       

        • Re: How to know number of Notification History Records
          MBanchuzhnyy

          I ‘d like to add that as you can see I'm using .GetInstances method of AFNotificationList class object. Is it possible to get history records using some other approach? Maybe if I used some other way, I would be able to get number of records and retrieve records by id number or somehow else.

           

          Thank you.

          • Re: How to know number of Notification History Records
            hanyong

            Hi Maxim,

             

            I am not aware of any ways to find a count of the total number of history record since the notification is created, or for a specific time range. So I can't suggest much in terms of how you can do it better, or how you can find the count without searching for the notification history first. 

             

            In the comments of your code snippet, you mentioned that you are getting all history record from the notification. In addition, your search condition in FindNotifications call is trying to find all defined notification as well. So essentially you are getting all history record for all notifications. I can see why it would take a long time to execute, if you have many notifications defined and also when there are a lot of events recorded in the history. May I ask what kind of analysis you are running that requires all the history record?

             

            As for other methods for getting the notification instances, instead of ANNotificationList.GetInstances call which gets the notification instance for all notifications in the collection, there is also ANNotication.GetInstances call that get the instances for a specific notification

              • Re: How to know number of Notification History Records
                pcombellick

                // Step1: when loading a bunch of objects, consider the "Load .. ( )" methods:

                 

                   // Find notifications to load.  As with all top-level objects, the

                 

                   // notifications returned are only partially loaded into memory.  

                 

                   AFNamedCollectionList<AFNotification> notifications =

                 

                      AFNotification.FindNotifications(myDB, "", AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, 100);

                 

                   // The LoadNotifications call will fully load the notification into memory.

                 

                   // The second parameter indicates whether the analysis should be loaded as well.

                 

                   // For example, if you were going to display or edit analysis information, you would

                 

                   // set this parameter to true.

                 

                   AFNotification.LoadNotifications(notifications, false);

                  • Re: How to know number of Notification History Records
                    MBanchuzhnyy

                    Thank you for answers. I appreciate it. I'll try to use your advises.

                     

                    Regarding "May I ask what kind of analysis you are running that requires all the history record?" - It's just common purpose application which allows to show notification history for noted time frame. Since we have 1-10k notifications, and each has pretty long history, in case user (even accidentally) selects 2-3 month period of time, it kills web service, that's why I'm trying to develop some algorithm to control number of retrieving data per one web service request, and of course I need to know all history records amount...

                     

                    Maybe somebody has something else to add. Thank you again.