Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93074231
PhabricatorCursorPagedPolicyQuery.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 26, 00:30
Size
3 KB
Mime Type
text/x-php
Expires
Thu, Nov 28, 00:30 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22568074
Attached To
rPH Phabricator
PhabricatorCursorPagedPolicyQuery.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A query class which uses cursor-based paging. This paging is much more
* performant than offset-based paging in the presence of policy filtering.
*/
abstract
class
PhabricatorCursorPagedPolicyQuery
extends
PhabricatorPolicyQuery
{
private
$afterID
;
private
$beforeID
;
protected
function
getPagingColumn
()
{
return
'id'
;
}
protected
function
getPagingValue
(
$result
)
{
return
$result
->
getID
();
}
protected
function
nextPage
(
array
$page
)
{
if
(
$this
->
beforeID
)
{
$this
->
beforeID
=
$this
->
getPagingValue
(
head
(
$page
));
}
else
{
$this
->
afterID
=
$this
->
getPagingValue
(
last
(
$page
));
}
}
final
public
function
setAfterID
(
$object_id
)
{
$this
->
afterID
=
$object_id
;
return
$this
;
}
final
public
function
setBeforeID
(
$object_id
)
{
$this
->
beforeID
=
$object_id
;
return
$this
;
}
final
protected
function
buildLimitClause
(
AphrontDatabaseConnection
$conn_r
)
{
if
(
$this
->
getLimit
())
{
return
qsprintf
(
$conn_r
,
'LIMIT %d'
,
$this
->
getLimit
());
}
else
{
return
''
;
}
}
final
protected
function
buildPagingClause
(
AphrontDatabaseConnection
$conn_r
)
{
if
(
$this
->
beforeID
)
{
return
qsprintf
(
$conn_r
,
'%Q > %s'
,
$this
->
getPagingColumn
(),
$this
->
beforeID
);
}
else
if
(
$this
->
afterID
)
{
return
qsprintf
(
$conn_r
,
'%Q < %s'
,
$this
->
getPagingColumn
(),
$this
->
afterID
);
}
return
null
;
}
final
protected
function
buildOrderClause
(
AphrontDatabaseConnection
$conn_r
)
{
if
(
$this
->
beforeID
)
{
return
qsprintf
(
$conn_r
,
'ORDER BY %Q ASC'
,
$this
->
getPagingColumn
());
}
else
{
return
qsprintf
(
$conn_r
,
'ORDER BY %Q DESC'
,
$this
->
getPagingColumn
());
}
}
final
protected
function
processResults
(
array
$results
)
{
if
(
$this
->
beforeID
)
{
$results
=
array_reverse
(
$results
,
$preserve_keys
=
true
);
}
return
$results
;
}
final
public
function
executeWithCursorPager
(
AphrontCursorPagerView
$pager
)
{
$this
->
setLimit
(
$pager
->
getPageSize
()
+
1
);
if
(
$pager
->
getAfterID
())
{
$this
->
setAfterID
(
$pager
->
getAfterID
());
}
else
if
(
$pager
->
getBeforeID
())
{
$this
->
setBeforeID
(
$pager
->
getBeforeID
());
}
$results
=
$this
->
execute
();
$sliced_results
=
$pager
->
sliceResults
(
$results
);
if
(
$this
->
beforeID
||
(
count
(
$results
)
>
$pager
->
getPageSize
()))
{
$pager
->
setNextPageID
(
$this
->
getPagingValue
(
last
(
$sliced_results
)));
}
if
(
$this
->
afterID
||
(
$this
->
beforeID
&&
(
count
(
$results
)
>
$pager
->
getPageSize
())))
{
$pager
->
setPrevPageID
(
$this
->
getPagingValue
(
head
(
$sliced_results
)));
}
return
$sliced_results
;
}
}
Event Timeline
Log In to Comment