MagmaCollectionReader sortBy: total number of elements in list?

Bart Gauquie bart.gauquie at gmail.com
Sun Dec 6 09:26:01 UTC 2009


Dear all,

I've been using the MagmaCollectionReader to develop a paged view over some
collection. I'm using this paged view in a seaside app. This shows if there
is a previous or a next page and the number of items being shown now: 1 - 21
of 2867.

If I do a query on a MagmaCollection using a sortBy: clause; some things go
sometimes a bit wrong.

If I do a query using a sortBy: ; then i can check if sortComplete. Using a
query without sortBy:, I can know the total number of items by calling
lastKnownSize. If I do a sortBy: query, the lastKnownSize returns the max
number already sorted (which is not ok in my gui; I need the total of that
query). However I noticed that u can also use fractionSorted to know how
much items already have been sorted, and derived from that how much items
there are in total.

For instance:

Last known size: 2249
Fraction Sorted:(2249/6065)

So I wrote code like this to already know and show the total numbers of the
search, even if the search is still going on on the server, like this I can
then already show the first page with the result, while the server is still
creating further pages

totalNumberOfElements
   ^(magmaCollectionReader sortComplete)
        ifTrue: [magmaCollectionReader lastKnownSize]
        ifFalse: [|fractionSorted|
            fractionSorted := magmaCollectionReader fractionSorted.
            (fractionSorted = 0)
               ifTrue: [self totalNumberOfElements].
            (fractionSorted isFraction)
               ifTrue: [fractionSorted denominator]
               ifFalse: [magmaCollectionReader lastKnownSize]]].

This works mostly. If the fraction gets reduced however, the denominator
returns a too low number off course. Is there any other way to know the
total number of items in the search, even if it is still going on the
server?

If I follow the code into
MaQueryExecutor>>fractionComplete
    ^ trunkPosition
          ifNil: [ 0 ]
          ifNotNil:
             [ | trunkSize |
               trunkSize _ self trunk trunkSize.
               trunkSize = 0
                  ifTrue: [ 1 ]
                  ifFalse: [ trunkPosition / self trunk trunkSize ] ]

I understand where the 0 can come from & where the reduction comes from.
Integer/anotherInteger automatically does a reduce.

If I on the server Image change
MaQueryExecutor>>fractionComplete
       ^ trunkPosition
             ifNil: [ 0 ]
             ifNotNil:
                 [ | trunkSize |
                    trunkSize _ self trunk trunkSize.
                    trunkSize = 0
                        ifTrue: [ 1 ]
                        ifFalse: [* Fraction numerator: trunkPosition
denominator: self trunk trunkSize* ] ]

It works because the reduce is then not done. This is a bit of hack off
course.

Is there any other way of doing this?


Thanks for any help.

Kind Regards

Bart

-- 
imagination is more important than knowledge - Albert Einstein
Logic will get you from A to B. Imagination will take you everywhere -
Albert Einstein
Learn from yesterday, live for today, hope for tomorrow. The important thing
is not to stop questioning. - Albert Einstein
The true sign of intelligence is not knowledge but imagination. - Albert
Einstein
Gravitation is not responsible for people falling in love. - Albert Einstein
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/magma/attachments/20091206/2d022aa9/attachment.htm


More information about the Magma mailing list