Skip to content

Commit

Permalink
Improvements to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
mtabacman committed Mar 22, 2024
1 parent 2aad432 commit bf216d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
8 changes: 7 additions & 1 deletion source/Sagan-Core/InMemoryRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ InMemoryRepository >> conflictCheckingStrategy [
^ conflictCheckingStrategy
]

{ #category : 'querying' }
InMemoryRepository >> countAll [

^ contents size
]

Check warning on line 45 in source/Sagan-Core/InMemoryRepository.class.st

View check run for this annotation

Codecov / codecov/patch

source/Sagan-Core/InMemoryRepository.class.st#L42-L45

Added lines #L42 - L45 were not covered by tests

{ #category : 'querying' }
InMemoryRepository >> countMatching: aCriteriaOrBlockClosure [

Expand All @@ -51,7 +57,7 @@ InMemoryRepository >> findAll [
]

{ #category : 'querying' }
InMemoryRepository >> findAllFrom: aFromIndex to: aToIndex sortedBy: anIndexName [
InMemoryRepository >> findAllFrom: aFromIndex upTo: aToIndex sortedBy: anIndexName [

| from to |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,27 @@ GemStoneRepositoryProviderTest >> testQueryingInterval [
store: self silvesterStallone
].

result := self extraterrestrials findAllFrom: 1000 to: 1001 sortedBy: 'lastName'.
result := self extraterrestrials findAllFrom: 1000 upTo: 1001 sortedBy: 'lastName'.
self assert: result size equals: 2.
self assert: ( result first firstName = 'John' and: [ result first lastName = 'Lock' ] ).
self assert: ( result last firstName = 'Silvester' and: [ result last lastName = 'Stallone' ] ).

result := self extraterrestrials findAllFrom: 4000 to: 4005 sortedBy: 'lastName'.
result := self extraterrestrials findAllFrom: 4000 upTo: 4005 sortedBy: 'lastName'.
self
withTheOnlyOneIn: result
do: [ :extraterrestrial | self assert: extraterrestrial lastName equals: 'Travolta' ].
result := self extraterrestrials findAllFrom: 4000 to: 4005 sortedBy: 'firstName'.
result := self extraterrestrials findAllFrom: 4000 upTo: 4005 sortedBy: 'firstName'.
self withTheOnlyOneIn: result do: [ :extraterrestrial |
self
assert: extraterrestrial firstName equals: 'Silvester';
assert: extraterrestrial lastName equals: 'Stallone'
].

result := self extraterrestrials findAllFrom: -50 to: 0 sortedBy: 'lastName'.
result := self extraterrestrials findAllFrom: -50 upTo: 0 sortedBy: 'lastName'.
self assert: result isEmpty.
result := self extraterrestrials findAllFrom: 6 to: -2 sortedBy: 'lastName'.
result := self extraterrestrials findAllFrom: 6 upTo: -2 sortedBy: 'lastName'.
self assert: result isEmpty.
result := self extraterrestrials findAllFrom: 5000 to: 10000 sortedBy: 'lastName'.
result := self extraterrestrials findAllFrom: 5000 upTo: 10000 sortedBy: 'lastName'.
self assert: result isEmpty
]

Expand Down
22 changes: 16 additions & 6 deletions source/Sagan-GemStone/GemStoneRepository.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ GemStoneRepository >> conflictCheckingStrategy [
^ conflictCheckingStrategy
]

{ #category : 'querying' }
GemStoneRepository >> countAll [

^ contents size
]

{ #category : 'querying' }
GemStoneRepository >> countMatching: aCriteriaOrBlockClosure [

Expand All @@ -51,19 +57,23 @@ GemStoneRepository >> findAll [
]

{ #category : 'querying' }
GemStoneRepository >> findAllFrom: aFromIndex to: aToIndex sortedBy: anIndexName [
GemStoneRepository >> findAllFrom: aStartingPosition upTo: aMaximumPosition sortedBy: anIndexName [

| results |

results := OrderedCollection new.
self withQueryFrom: ( 'each.<1s> >= ''''' expandMacrosWith: anIndexName asString ) do: [ :query |
| stream start limit |
| stream skipped limit |

stream := query readStream.
start := aFromIndex - 1 max: 0.
limit := aToIndex - start max: 0.
stream skip: start.
limit timesRepeat: [ stream atEnd ifFalse: [ results add: stream next ] ]
skipped := aStartingPosition - 1 max: 0.
limit := aMaximumPosition - skipped max: 0.
stream skip: skipped.
limit timesRepeat: [
stream atEnd
ifTrue: [ ^ results ]
ifFalse: [ results add: stream next ]
]
].
^ results
]
Expand Down

0 comments on commit bf216d6

Please sign in to comment.