Page MenuHomePhabricator

Check if the page content has changed before trying to save it (in Page.put)
Closed, DeclinedPublic

Description

It seems that Page.put method always tries to send a web request to save the page, even if the newtext parameter is the same as the current text.

Although this can be done manually, I think it's still a good idea to compare page.text with the newtext parameter passed to page.put before trying to save it and avoid the unnecessary web request.

This simple comparison does not seem to cost much processing time at all, but in those cases that the user has not checked the change, it can reduce server load and improve script's speed a little bit.

Users that want to avoid this comparison will be able to use Page.save directly.

Event Timeline

Dalba created this task.Jan 1 2016, 5:57 AM
Dalba raised the priority of this task from to Needs Triage.
Dalba updated the task description. (Show Details)
Dalba added projects: Pywikibot, good first bug.
Dalba added a subscriber: Dalba.
Dalba renamed this task from Check if the page content has changed (in Page.put) to Check if the page content has changed before trying to save it (in Page.put).Jan 1 2016, 6:11 AM
Dalba set Security to None.

This is a breaking change. Some users may send intentionally null edits to refresh server caches.

Dalba added a comment.Jan 1 2016, 7:42 AM

Oh, good point!
Even in that case, forcerecursivelinkupdate seems a better choice to me, but maybe it's not worth it anymore. Should I mark this task as declined?

BasePage.purge() with forcerecursivelinkupdate should be preferred but some users may still be using BasePage.put() for the purpose. Although I'm not dismissing the proposed change at first glance, I don't think the framework should get in its users' way.

Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptSep 24 2016, 1:56 PM

Change 312721 had a related patch set uploaded (by Vyeshwanth):
pywikibot.Page.put: checking the changes before saving

https://gerrit.wikimedia.org/r/312721

Xqt added a subscriber: Xqt.Sep 27 2016, 8:46 AM

Some notes of my pov

  • as Ricordisamoa mentioned this would be a breaking change and unables null-edits
  • we would have a different behaviour for put() put_async() and save() but we should avoid this
  • user messages should be avoided in library parts except they are exceptions
  • put() and put_async() are more deprecated methods; save() should used instead
  • we have putting methods inside bot classes. If at all I guess this test should made inside put_current or userPut and have an additional option.
Xqt closed this task as Declined.Sep 29 2016, 8:34 AM

BaseBot.userPut() does it already.

@Vyeshwant123 Sorry about that!
I'd recommend you go ahead and find another bug to solve :)

Change 312721 abandoned by Xqt:
pywikibot.Page.put: checking the changes before saving

Reason:
per T122715

https://gerrit.wikimedia.org/r/312721