Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pagination with 'continue' to load all linked pages #6068

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/training/wiki_training_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@ def training_content_and_translations(content:, base_page:, wikitext:)

# Gets a list of page titles linked from the base page
def wiki_source_pages
# To handle more than 500 pages linked from the source page,
# we'll need to update this to use 'continue'.
source_pages = []
query_params = { prop: 'links', titles: @wiki_base_page, pllimit: 500 }
response = WikiApi.new(MetaWiki.new).query(query_params)
begin
response.data['pages'].values[0]['links'].map { |page| page['title'] }
rescue StandardError
raise InvalidWikiContentError, "could not get links from '#{@wiki_base_page}'"
loop do
response = WikiApi.new(MetaWiki.new).query(query_params)

begin
source_pages.concat(response.data['pages'].values[0]['links'].map { |page| page['title'] })
rescue StandardError
raise InvalidWikiContentError, "could not get links from '#{@wiki_base_page}'"
end

break unless response.data['continue']

query_params.merge!(response.data['continue'])
end

source_pages
end

def listed_wiki_source_pages
Expand Down
Loading