Uploaded image for project: '[Read Only] - Hippo Plugins'
  1. [Read Only] - Hippo Plugins
  2. HIPPLUG-111

Plugins use Query with ordering without setting limit

    XMLWordPrintable

Description

    ALL PLUGINS NEED TO BE CHECKED FOR THIS!!

    The query.execute() will authenticate ALL found results without any limits when no limit is set and ordering is used. The limit can be set by casting the Query to a HippoQuery and calling query.setLimit(). This method is also part of JCR 2.0 and as such will be available in 7.5 lifting the requirement to cast to a HippoQuery.

    A good example where this is implemented wrongly is the SimilaritySearchRelatedDocsProvider:

    ----------------------------------------- WRONG !! ---------------------------------------------------------------------
    Query query = nodeModel.getNode().getSession().getWorkspace().getQueryManager().createQuery(
    statement.toString(), Query.XPATH);

    RowIterator r = query.execute().getRows();
    int i = 0;
    while (r.hasNext() && i < 25)

    { // some code i++; }

    ----------------------------------------- WRONG !! ---------------------------------------------------------------------
    The limit off 25(hardcoded!!??!!) only works for the loop iteration. The query.execute() already has fetched EVERY (thousands!) node that matches the query from the database. As this will exceed the amount of cache available this will cause an extreme amount of IO.

    This should become something like:

    -----------------------------------------------------------------------------------------------------------------------------------------------
    HippoQuery query = (HippoQuery) nodeModel.getNode().getSession().getWorkspace().getQueryManager().createQuery(
    statement.toString(), Query.XPATH);

    query.setLimit(maxSimilarities);
    RowIterator r = query.execute().getRows();
    while (r.hasNext())

    { // some code }

    -----------------------------------------------------------------------------------------------------------------------------------------------

    Please consult with Ard if you have a query and you are not sure how to fix it.

    Attachments

      Issue Links

        Activity

          People

            mmilicevic Marijan Milicevic
            bvdschans Bart van der Schans (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: