Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25895

The REST modifications resource sorts the whole revision history of the wiki when no date is given

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 18.4.6
    • REST
    • Unknown

    Description

      Steps to reproduce

      1. On a wiki with a large history (e.g. www.xwiki.org), request /rest/wikis/xwiki/modifications without the date parameter.

      Expected

      The 25 most recent modifications are returned quickly.

      Actual

      The request takes about 27 seconds on xwiki.org, nearly all of it in a single SQL query that returns 25 rows:

      select doc.XWD_WEB, doc.XWD_NAME, doc.XWD_LANGUAGE, rcs.XWR_DOCID, rcs.XWR_VERSION1, rcs.XWR_VERSION2, rcs.XWR_DATE, rcs.XWR_AUTHOR, rcs.XWR_COMMENT
      from xwikircs rcs cross join xwikidoc doc
      where rcs.XWR_DOCID = doc.XWD_ID and rcs.XWR_DATE > ?
      order by rcs.XWR_DATE desc, rcs.XWR_VERSION1 desc, rcs.XWR_VERSION2 desc limit ?
      

      This isn't caused by load: a single request reproduced on an otherwise normal xwiki.org node took 30.4 seconds, 30.3 of them in this query.

      date defaults to 0 (ModificationsResource), so the condition matches every revision of the wiki. The REV_DATE index only covers XWR_DATE; in InnoDB a secondary index is implicitly followed by the primary key (XWR_DOCID, XWR_VERSION1, XWR_VERSION2), so it can't produce the order XWR_DATE, XWR_VERSION1, XWR_VERSION2 and the database sorts all revisions joined with their documents before applying the limit. Anonymous crawlers can trigger this on every wiki of a farm in parallel.

      Possible fixes

      • Order by rcs.date only (or by rcs.date, rcs.id.docId, rcs.id.version1, rcs.id.version2, which matches the index), so the database can scan the date index backwards and stop after start + number rows.
      • Or add an index on (XWR_DATE, XWR_VERSION1, XWR_VERSION2) (needs a migration on a big table).

      Attachments

        Activity

          People

            Unassigned Unassigned
            MichaelHamann Michael Hamann
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: