Revision: 6672 Author: nicdumz Date: 2009-04-22 17:45:07 +0000 (Wed, 22 Apr 2009)
Log Message: ----------- Do not parse the page N+1 times for interwikis, where N is the number of commented interwiki links. *Kof* *Kof*... =)
Modified Paths: -------------- trunk/pywikipedia/interwiki.py
Modified: trunk/pywikipedia/interwiki.py =================================================================== --- trunk/pywikipedia/interwiki.py 2009-04-22 17:09:48 UTC (rev 6671) +++ trunk/pywikipedia/interwiki.py 2009-04-22 17:45:07 UTC (rev 6672) @@ -1191,6 +1191,8 @@ # clone original newPages dictionary, so that we can modify it to the local page's needs new = dict(newPages)
+ interwikis = page.interwiki() + # remove interwiki links to ignore for iw in re.finditer('<!-- *\[\[(.*?:.*?)\]\] *-->', pagetext): try: @@ -1200,7 +1202,8 @@
try: if (new[ignorepage.site()] == ignorepage) and (ignorepage.site() != page.site()): - if (ignorepage not in page.interwiki()): + + if (ignorepage not in interwikis): wikipedia.output(u"Ignoring link to %(to)s for %(from)s" % {'to': ignorepage.aslink(), 'from': page.aslink()}) new.pop(ignorepage.site()) else: @@ -1222,7 +1225,7 @@ # Put interwiki links into a map old={} try: - for page2 in page.interwiki(): + for page2 in interwikis: old[page2.site()] = page2 except wikipedia.NoPage: wikipedia.output(u"BUG>>> %s no longer exists?" % page.aslink(True))
pywikipedia-svn@lists.wikimedia.org