8 Replies Latest reply on Dec 29, 2008 6:25 PM by Newsgroup_User

    Collection filtering performance issue

    rtalton Level 4
      I'm filtering a XMLListCollection by date. The date in the Collection has to be >= today's date, and then a List component using it as a dataProvider will show only items with an item date >= today.

      Today I ran into an issue where if there are no items matching this criteria, the List opens up empty. Confusing. So I added a line after the List's filter is applied to check if the length property of the dataProvider == 0 after filtering. If so, I remove the filter, and apply the refresh() method, and now all items are showing. This seems terribly inefficient and makes the List flicker, but I can't think of a way to check for zero items before a filter is applied.

      Any ideas on how I could do this efficiently?
        • 1. Re: Collection filtering performance issue
          Level 7
          Try just running the e4x expression that's the same as the filter and
          checking its length. Or use that instead of a filterFunction to come up
          with the XMLList in the first place.

          HTH;

          Amy

          "rtalton" <webforumsuser@macromedia.com> wrote in message
          news:gjavn6$7s3$1@forums.macromedia.com...
          > I'm filtering a XMLListCollection by date. The date in the Collection has
          > to be
          >>= today's date, and then a List component using it as a dataProvider will
          >>show
          > only items with an item date >= today.
          >
          > Today I ran into an issue where if there are no items matching this
          > criteria,
          > the List opens up empty. Confusing. So I added a line after the List's
          > filter
          > is applied to check if the length property of the dataProvider == 0 after
          > filtering. If so, I remove the filter, and apply the refresh() method, and
          > now
          > all items are showing. This seems terribly inefficient and makes the List
          > flicker, but I can't think of a way to check for zero items before a
          > filter is
          > applied.
          >
          > Any ideas on how I could do this efficiently?
          >


          • 2. Re: Collection filtering performance issue
            rtalton Level 4
            Thanks Amy, that helped. Only problem I had was I got an error when trying to filter my XMLListCollection directly "Can't apply e4x filtering to...", or something like that. Didn't know that was a no-no as I'd never tried it before.
            I created a temp var as XMLList, assigned the HTTPService's lastResult (e4x format) to it with an e4x filtering expression, and checked its length:

            var tempList:XMLList = new XMLList;
            tempList = eventsService.lastResult..event.(eventdate >= startDate);
            if (tempList.length > 0){
            //..calls function to filter XMLListCollection here...
            }

            This worked fine. Any comments on doing it this way?
            Thanks again for your assistance!
            • 3. Re: Collection filtering performance issue
              ntsiii Level 3
              * you do not need to "new" the XMLList
              * don't use lastResult in code. Use event.result. lastResult can be overwritten, nulled, etc by the framework outside of your control. It is rarely a problem in simple apps, but still..
              * With XMLList, always use the *method*, with the parens, length() to check the length.

              Tracy
              • 4. Re: Collection filtering performance issue
                rtalton Level 4
                I made the changes you suggested, thanks.
                One question...
                When I create the XMLList and do the e4x filtered assignment to it, the length property is not available in the debug window (if there is no data as a result of the filter), so I can't see the length prop at all. That's why I tried the new keyword, but that didn't expose the length prop, either.
                I've run into this before, but never found out why this is. Do you know?
                • 5. Re: Collection filtering performance issue
                  Level 7

                  "rtalton" <webforumsuser@macromedia.com> wrote in message
                  news:gjb9sg$k87$1@forums.macromedia.com...
                  >I made the changes you suggested, thanks.
                  > One question...
                  > When I create the XMLList and do the e4x filtered assignment to it, the
                  > length
                  > property is not available in the debug window (if there is no data as a
                  > result
                  > of the filter), so I can't see the length prop at all. That's why I tried
                  > the
                  > new keyword, but that didn't expose the length prop, either.
                  > I've run into this before, but never found out why this is. Do you know?

                  If you're talking about in the expressions window, look at this:
                  http://flexdiary.blogspot.com/2008/03/debugger-and-e4x.html

                  Also, be aware that length on an XMLList is a method, not a property, so you
                  actually have to _call_ the method to retrieve the length...you can't
                  inspect it as if it were a property.

                  HTH;

                  Amy


                  • 6. Re: Collection filtering performance issue
                    rtalton Level 4
                    Hi Amy!
                    Yeah, I knew the expressions window cannot parse e4x expressions. I'm talking about the variables window not showing props for a var within my function when I assign data using an e4x expression. I just though if I created a var as XMLList, it would have a length prop, even before any assignments to it.
                    • 7. Re: Collection filtering performance issue
                      rtalton Level 4
                      I just re-read your reply..."length on an XMLList is a method, not a property" that answers my question, thanks again!
                      • 8. Re: Collection filtering performance issue
                        Level 7

                        "rtalton" <webforumsuser@macromedia.com> wrote in message
                        news:gjbhrf$lk$1@forums.macromedia.com...
                        >I just re-read your reply..."length on an XMLList is a method, not a
                        >property" that answers my question, thanks again!

                        You're welcome :-)