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

fixes 500 link limit issue #5595

Closed
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
37 changes: 24 additions & 13 deletions lib/training/wiki_training_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def load_from_wiki
def add_trainings_to_collection(wiki_page)
content = new_from_wiki_page(wiki_page)
unless content&.valid?
Sentry.capture_message 'Invalid wiki training content',
level: 'warning', extra: { content:, wiki_page: }
return
Sentry.capture_message 'Invalid wiki training content',
level: 'warning', extra: { content: content, wiki_page: wiki_page }
return
end
@collection << content
end
end

def new_from_wiki_page(wiki_page)
wikitext = WikiApi.new(MetaWiki.new).get_page_content(wiki_page)
Expand All @@ -70,9 +70,11 @@ def new_from_json_wiki_page(json_wikitext)
content = Oj.load(json_wikitext)
base_page = content['wiki_page']
return content unless base_page

wikitext = WikiApi.new(MetaWiki.new).get_page_content(base_page)
training_content_and_translations(content:, base_page:, wikitext:)
end
training_content_and_translations(content: content, base_page: base_page, wikitext: wikitext)
end


# wikitext pages have the slide id and slug embedded in the page title
def new_from_wikitext_page(wiki_page, wikitext)
Expand All @@ -93,15 +95,24 @@ 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'.

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}'"
links = []

until @continue == 'done'
response = WikiApi.new(MetaWiki.new).query(query_params.merge(plcontinue: @continue))

begin
current_links = response.dig('pages', @wiki_base_page, 'links') || []
links.concat(current_links.map { |page| page['title'] })

@continue = response['continue']&.fetch('plcontinue', 'done')
rescue StandardError => e
raise InvalidWikiContentError, "could not get links from '#{@wiki_base_page}': #{e.message}"
end
end

links
end

def listed_wiki_source_pages
Expand Down
Loading