MagmaCollectionReader sortBy: total number of elements in list?

Chris Muller asqueaker at gmail.com
Wed Dec 9 05:20:29 UTC 2009


Hi Bart,

I had to re-read my own docs on the swiki to remember how this works..
 I might be confused, but sorting should not affect the size.  So you
should be able to do a #where:, then check the #lastKnownSize, then
sort.  The (#where: aBlock distinct: makeDistinct sortBy:
attributeSymbol descending: shouldDescend) message is just a
convenience method that does them both at once.  If you need to know
the size before sorting, I think they can be done separately.

Otherwise, I rather like your hack..  I don't see any harm in it, and
it does convey "more information" for checking the overall progress of
the background load on the server..

 - Chris


On Sun, Dec 6, 2009 at 3:26 AM, Bart Gauquie <bart.gauquie at gmail.com> wrote:
> 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
>
> _______________________________________________
> Magma mailing list
> Magma at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/magma
>
>


More information about the Magma mailing list