Skip to content

4.5.1a: WebDAV breaks at 999 files per directory #239

Closed

Description

@germeier

Hi there,
after upgrading to 4.5.0 I noticied that some of my backup tools stopped syncing data to OC.

How to reproduce:

  • Clean install of owncloud 4.5.1a
  • mkdir 1; cd 1
  • generate 998 files: a=1 ; while [ $a -lt 999 ] ; do touch $a ; a=$(($a+1)) ; done
  • check directory via webfrontend
  • check directory via WebDAV (in browser) (both are fine)
  • generate a 999th file
  • check directory via webfrontend -> all 999 files are fine
  • check directory via WebDAV (in browser):
    DB Error: "SQLSTATE[HY000]: General error: 1 too many SQL variables"
    Offending command was: SELECT * FROM "oc_properties" WHERE "userid" = ? AND "propertypath" IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,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?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

This was checked against a clean install of 4.5.1a. A clean install of 4.0.8 works fine for me. Updating SabreDAV to 1.6.5 does not change the problem.

Regards,
Markus

Activity

  1. DeepDiver1975 commented on Nov 5, 2012

    @DeepDiver1975
    Contributor

    @evert
    Can you help us out on this? THX a lot!

  2. evert commented on Nov 5, 2012

    @evert

    Where's the code for this?

  3. DeepDiver1975 commented on Nov 5, 2012

    @DeepDiver1975
    Contributor

    Hehe - took me some time to find the code.
    Actually this is not SabreDAV related - @evert sorry for the noise.

    The problem is here:
    https://github.com/owncloud/core/blob/master/lib/connector/sabre/directory.php#L128

    $placeholders needs to be chunked in packs of 1000 items max.

  4. evert commented on Nov 5, 2012

    @evert

    I had a hunch.. It actually looks like you may be able to use a LIKE query instead though..

  5. DeepDiver1975 commented on Nov 5, 2012

    @DeepDiver1975
    Contributor

    Looks like

  6. scroogie commented on Nov 5, 2012

    @scroogie

    Would the shared files need to be special cased then? (When using a prefix scan). Btw, I think mysql is able to use an index in a LIKE prefix% query.

  7. dragotin commented on Nov 5, 2012

    @dragotin
    Contributor

    @icewind1991
    @DeepDiver1975

    This patch solves the problem for me:

    diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
    index 413efef..37238dc 100644
    --- a/lib/connector/sabre/directory.php
    +++ b/lib/connector/sabre/directory.php
    @@ -124,10 +124,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
                    }
                    $properties = array_fill_keys($paths, array());
                    if(count($paths)>0) {
    -                       $placeholders = join(',', array_fill(0, count($paths), '?'));
    -                       $query = OC_DB::prepare( 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ?' . ' AND `propertypath` IN ('.$placeholders.')' );
    -                       array_unshift($paths, OC_User::getUser()); // prepend userid
    -                       $result = $query->execute( $paths );
    +                       $query = OC_DB::prepare( 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` =?');
    +                       $params = array();
    +                       $params[] = OC_User::getUser();
    +
    +                       foreach($paths as $path) {
    +                               $params[1] = $path;
    +
    +                               $result = $query->execute($params);
    +
                            while($row = $result->fetchRow()) {
                                    $propertypath = $row['propertypath'];
                                    $propertyname = $row['propertyname'];
    @@ -135,7 +140,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
                                    $properties[$propertypath][$propertyname] = $propertyvalue;
                            }
                    }
    -
    +               }
                    $nodes = array();
                    foreach($folder_content as $info) {
                            $node = $this->getChild($info['name'], $info);

    Please review deeply, I am not very much into PHP. It loops over all the children which should be fine as long the prepare is outside the loop. IN should be used carefully.

  8. DeepDiver1975 commented on Nov 5, 2012

    @DeepDiver1975
    Contributor

    I'll do some test on this.

  9. DeepDiver1975 commented on Nov 5, 2012

    @DeepDiver1975
    Contributor

    My setup: apache + sqlite
    current implementation: 0.1331 sec.
    proposal above: 0.5020 sec
    chunked in packs of 999: 0.3075 sec

  10. scroogie commented on Nov 5, 2012

    @scroogie

    How many records does the table have in the above tests?

  11. DeepDiver1975 commented on Nov 5, 2012

    @DeepDiver1975
    Contributor

    I did setup a clean new installation for testing this: 998 entries.

  12. locked as resolved and limited conversation to collaborators on Aug 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions