Timeout when retrieving results from Wikidata

249 views Asked by At

This query for retrieving movie posters from Wikidata results in "Query timeout limit reached" errors on query.wikidata.org:

#defaultView:ImageGrid
SELECT ?item ?itemLabel ?pic ?fileTitle ?width ?height
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q11424 .
  ?item wdt:P3383 ?pic .
  BIND(STRAFTER(wikibase:decodeUri(STR(?pic)), "http://commons.wikimedia.org/wiki/Special:FilePath/") AS ?fileTitle)

  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" 
  }

  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:endpoint "commons.wikimedia.org";
                    wikibase:api "Generator";
                    wikibase:limit "once";
                    mwapi:generator "allpages";
                    mwapi:gapfrom ?fileTitle;
                    mwapi:gapnamespace 6; # NS_FILE
                    mwapi:gaplimit 1;
                    mwapi:prop "imageinfo";
                    mwapi:iiprop "dimensions".
    ?size wikibase:apiOutput "imageinfo/ii/@size".
    ?width wikibase:apiOutput "imageinfo/ii/@width".
    ?height wikibase:apiOutput "imageinfo/ii/@height".
  }

}
ORDER BY ?item
LIMIT 100
OFFSET 0

Setting a low limit works, with fewer than 100 results, and removing ORDER BY. However, ORDER BY is necessary to ensure that subsequent queries retrieve all results, and adding ORDER BY ?item throws a timeout error again. Ideally, I would like to filter by posters with a minimum width, but adding FILTER(?width>1500) times out no matter how low the limit.

Any suggestions for optimising the query to work consistently and reliably? Even if it only returns a single value, the query can be repeated until all values have been retrieved.

0

There are 0 answers