Skip to content

Use the defined func()->count() instead of manual counting - #11942

Merged
MorrisJobke merged 1 commit into
masterfrom
techdebt/noid/use-count-function
Nov 12, 2018
Merged

Use the defined func()->count() instead of manual counting#11942
MorrisJobke merged 1 commit into
masterfrom
techdebt/noid/use-count-function

Conversation

@nickvergessen

Copy link
Copy Markdown
Member

Now there are only 2 "functions" left which are both called twice and don't have a wrapper:

  • GREATEST
  • COUNT(DISTINCT …)

Not sure if it's worth the effort.

@nickvergessennickvergessen added 3. to review Waiting for reviews technical debt 🧱 🤔🚀 labels Oct 19, 2018
@nickvergessennickvergessen added this to the Nextcloud 15 milestone Oct 19, 2018

public function count($input) {
return new QueryFunction('COUNT(' . $this->helper->quoteColumnName($input) . ')');
public function count($count, $alias = '') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't alias work by just using selectAlias($qb->func()->count(...), 'alias')

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i added it here because its done quite often

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having it here doesn't make sense to me though, since for the caller it's not any easier (the only difference is where you place the )) and it's duplicating code/functionality

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this here. It also reduces function nesting.

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good 👍

@MorrisJobkeMorrisJobke mentioned this pull request Nov 6, 2018
29 tasks
@MorrisJobke

Copy link
Copy Markdown
Member

@icewind1991@rullzer Any comments on this one?

@icewind1991icewind1991 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me

@MorrisJobke

Copy link
Copy Markdown
Member

Yay PHPunit tests fail 😢 I should have checked that earlier

@MorrisJobke

Copy link
Copy Markdown
Member

Yay PHPunit tests fail 😢 I should have checked that earlier

Ah - disk was just full -> let's do another round: https://drone.nextcloud.com/nextcloud/server/12482

@MorrisJobkeMorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Nov 7, 2018
@MorrisJobke

Copy link
Copy Markdown
Member

This causes the same "Disk is full" errors 😨

@MorrisJobkeMorrisJobke added 2. developing Work in progress and removed 4. to release Ready to be released and/or waiting for tests to finish labels Nov 7, 2018
@nickvergessen

Copy link
Copy Markdown
MemberAuthor

strange, let me investigate

@nickvergessen
nickvergessenforce-pushed the techdebt/noid/use-count-function branch 2 times, most recently from 08ee437 to 7365078CompareNovember 7, 2018 19:02
$qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'),
'num_ids'
)
->addSelect($qb->func()->count('c.id', 'num_ids'))

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MorrisJobke the problem was select here instead of addSelect which caused a lot of spam with missing index fileId across tests

@nickvergessennickvergessen added 4. to release Ready to be released and/or waiting for tests to finish and removed 2. developing Work in progress labels Nov 7, 2018
@MorrisJobke

Copy link
Copy Markdown
Member

Still this one:

Test\SystemTag\SystemTagObjectMapperTest::testHaveTagAllMatches
Doctrine\DBAL\Exception\InvalidFieldNameException: An exception occurred while executing 'SELECT COUNT(`1`) FROM `oc_systemtag_object_mapping` WHERE (`objectid` IN (?)) AND (`objecttype` = ?) AND (`systemtagid` = ?)' with params ["1", "testtype", "1"]:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list'
...

@nickvergessen

Copy link
Copy Markdown
MemberAuthor

fixed

@nickvergessen
nickvergessenforce-pushed the techdebt/noid/use-count-function branch from 7365078 to 82fb91bCompareNovember 8, 2018 11:21
@MorrisJobkeMorrisJobke mentioned this pull request Nov 8, 2018
24 tasks
@MorrisJobke

Copy link
Copy Markdown
Member

Fails on Postgres https://drone.nextcloud.com/nextcloud/server/12537/167:

1) Test\SystemTag\SystemTagObjectMapperTest::testHaveTagAllMatches
Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'SELECT COUNT(?) FROM "oc_systemtag_object_mapping" WHERE ("objectid" IN (?)) AND ("objecttype" = ?) AND ("systemtagid" = ?)' with params [1, "1", "testtype", "1"]:
SQLSTATE[42P18]: Indeterminate datatype: 7 ERROR: could not determine data type of parameter $1
/drone/src/github.com/nextcloud/server/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php:92
/drone/src/github.com/nextcloud/server/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:128
/drone/src/github.com/nextcloud/server/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:855
/drone/src/github.com/nextcloud/server/lib/private/DB/Connection.php:195
/drone/src/github.com/nextcloud/server/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php:206
/drone/src/github.com/nextcloud/server/lib/private/DB/QueryBuilder/QueryBuilder.php:214
/drone/src/github.com/nextcloud/server/lib/private/SystemTag/SystemTagObjectMapper.php:231
/drone/src/github.com/nextcloud/server/tests/lib/SystemTag/SystemTagObjectMapperTest.php:291

@MorrisJobkeMorrisJobke added the 2. developing Work in progress label Nov 8, 2018
@MorrisJobkeMorrisJobke removed the 4. to release Ready to be released and/or waiting for tests to finish label Nov 8, 2018
Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
nickvergessenforce-pushed the techdebt/noid/use-count-function branch from 82fb91b to bb352fbCompareNovember 8, 2018 14:44

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@MorrisJobke
MorrisJobke merged commit fd8eecc into masterNov 12, 2018
@MorrisJobke
MorrisJobke deleted the techdebt/noid/use-count-function branch November 12, 2018 16:44
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developingWork in progresstechnical debt🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@nickvergessen@MorrisJobke@icewind1991