Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
9a0950f1
Commit
9a0950f1
authored
Feb 23, 2016
by
Thomas Müller
Browse files
Merge pull request #22569 from owncloud/issue-22566-too-much-mapping-entries
Allow defining a limit and offset for getObjectIdsForTags
parents
fae6643e
3a65bdf4
Changes
4
Hide whitespace changes
Inline
Side-by-side
apps/dav/tests/unit/connector/sabre/filesreportplugin.php
View file @
9a0950f1
...
...
@@ -19,7 +19,7 @@
*
*/
namespace
OCA\DAV\Tests\Unit\
Sabre\
Connector
;
namespace
OCA\DAV\Tests\Unit\Connector
\Sabre
;
use
OCA\DAV\Connector\Sabre\FilesReportPlugin
as
FilesReportPluginImplementation
;
use
Sabre\DAV\Exception\NotFound
;
...
...
@@ -369,7 +369,7 @@ class FilesReportPlugin extends \Test\TestCase {
[
'123'
,
'files'
]
)
->
willReturnMap
([
[
'123'
,
'files'
,
[
'111'
,
'222'
]],
[
'123'
,
'files'
,
0
,
''
,
[
'111'
,
'222'
]],
]);
$rules
=
[
...
...
@@ -391,8 +391,8 @@ class FilesReportPlugin extends \Test\TestCase {
[
'456'
,
'files'
]
)
->
willReturnMap
([
[
'123'
,
'files'
,
[
'111'
,
'222'
]],
[
'456'
,
'files'
,
[
'222'
,
'333'
]],
[
'123'
,
'files'
,
0
,
''
,
[
'111'
,
'222'
]],
[
'456'
,
'files'
,
0
,
''
,
[
'222'
,
'333'
]],
]);
$rules
=
[
...
...
@@ -415,8 +415,8 @@ class FilesReportPlugin extends \Test\TestCase {
[
'456'
,
'files'
]
)
->
willReturnMap
([
[
'123'
,
'files'
,
[
'111'
,
'222'
]],
[
'456'
,
'files'
,
[]],
[
'123'
,
'files'
,
0
,
''
,
[
'111'
,
'222'
]],
[
'456'
,
'files'
,
0
,
''
,
[]],
]);
$rules
=
[
...
...
@@ -439,8 +439,8 @@ class FilesReportPlugin extends \Test\TestCase {
[
'456'
,
'files'
]
)
->
willReturnMap
([
[
'123'
,
'files'
,
[]],
[
'456'
,
'files'
,
[
'111'
,
'222'
]],
[
'123'
,
'files'
,
0
,
''
,
[]],
[
'456'
,
'files'
,
0
,
''
,
[
'111'
,
'222'
]],
]);
$rules
=
[
...
...
@@ -464,9 +464,9 @@ class FilesReportPlugin extends \Test\TestCase {
[
'789'
,
'files'
]
)
->
willReturnMap
([
[
'123'
,
'files'
,
[
'111'
,
'222'
]],
[
'456'
,
'files'
,
[
'333'
]],
[
'789'
,
'files'
,
[
'111'
,
'222'
]],
[
'123'
,
'files'
,
0
,
''
,
[
'111'
,
'222'
]],
[
'456'
,
'files'
,
0
,
''
,
[
'333'
]],
[
'789'
,
'files'
,
0
,
''
,
[
'111'
,
'222'
]],
]);
$rules
=
[
...
...
lib/private/systemtag/systemtagobjectmapper.php
View file @
9a0950f1
...
...
@@ -95,7 +95,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
/**
* {@inheritdoc}
*/
public
function
getObjectIdsForTags
(
$tagIds
,
$objectType
)
{
public
function
getObjectIdsForTags
(
$tagIds
,
$objectType
,
$limit
=
0
,
$offset
=
''
)
{
if
(
!
is_array
(
$tagIds
))
{
$tagIds
=
[
$tagIds
];
}
...
...
@@ -105,10 +105,21 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$query
=
$this
->
connection
->
getQueryBuilder
();
$query
->
select
(
$query
->
createFunction
(
'DISTINCT(`objectid`)'
))
->
from
(
self
::
RELATION_TABLE
)
->
where
(
$query
->
expr
()
->
in
(
'systemtagid'
,
$query
->
createParameter
(
'tagids'
)))
->
andWhere
(
$query
->
expr
()
->
eq
(
'objecttype'
,
$query
->
createParameter
(
'objecttype'
)))
->
setParameter
(
'tagids'
,
$tagIds
,
IQueryBuilder
::
PARAM_INT_ARRAY
)
->
setParameter
(
'objecttype'
,
$objectType
);
->
where
(
$query
->
expr
()
->
in
(
'systemtagid'
,
$query
->
createNamedParameter
(
$tagIds
,
IQueryBuilder
::
PARAM_INT_ARRAY
)))
->
andWhere
(
$query
->
expr
()
->
eq
(
'objecttype'
,
$query
->
createNamedParameter
(
$objectType
)));
if
(
$limit
)
{
if
(
sizeof
(
$tagIds
)
!==
1
)
{
throw
new
\
InvalidArgumentException
(
'Limit is only allowed with a single tag'
);
}
$query
->
setMaxResults
(
$limit
)
->
orderBy
(
'objectid'
,
'ASC'
);
if
(
$offset
!==
''
)
{
$query
->
andWhere
(
$query
->
expr
()
->
gt
(
'objectid'
,
$query
->
createNamedParameter
(
$offset
)));
}
}
$objectIds
=
[];
...
...
lib/public/systemtag/isystemtagobjectmapper.php
View file @
9a0950f1
...
...
@@ -57,15 +57,19 @@ interface ISystemTagObjectMapper {
*
* @param string|array $tagIds Tag id or array of tag ids.
* @param string $objectType object type
* @param int $limit Count of object ids you want to get
* @param string $offset The last object id you already received
*
* @return string[] array of object ids or empty array if none found
*
* @throws \OCP\SystemTag\TagNotFoundException if at least one of the
* given tags does not exist
* @throws \InvalidArgumentException When a limit is specified together with
* multiple tag ids
*
* @since 9.0.0
*/
public
function
getObjectIdsForTags
(
$tagIds
,
$objectType
);
public
function
getObjectIdsForTags
(
$tagIds
,
$objectType
,
$limit
=
0
,
$offset
=
''
);
/**
* Assign the given tags to the given object.
...
...
tests/lib/systemtag/systemtagobjectmappertest.php
View file @
9a0950f1
...
...
@@ -145,6 +145,42 @@ class SystemTagObjectMapperTest extends TestCase {
],
$objectIds
);
}
public
function
testGetObjectsForTagsLimit
()
{
$objectIds
=
$this
->
tagMapper
->
getObjectIdsForTags
(
[
$this
->
tag1
->
getId
()],
'testtype'
,
1
);
$this
->
assertEquals
([
1
,
],
$objectIds
);
}
/**
* @expectedException \InvalidArgumentException
*/
public
function
testGetObjectsForTagsLimitWithMultipleTags
()
{
$this
->
tagMapper
->
getObjectIdsForTags
(
[
$this
->
tag1
->
getId
(),
$this
->
tag2
->
getId
(),
$this
->
tag3
->
getId
()],
'testtype'
,
1
);
}
public
function
testGetObjectsForTagsLimitOffset
()
{
$objectIds
=
$this
->
tagMapper
->
getObjectIdsForTags
(
[
$this
->
tag1
->
getId
()],
'testtype'
,
1
,
'1'
);
$this
->
assertEquals
([
2
,
],
$objectIds
);
}
/**
* @expectedException \OCP\SystemTag\TagNotFoundException
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment