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

Use server time rather than client time wherever possible #741

Merged
merged 3 commits into from Jan 7, 2020

Conversation

siddharthvp
Copy link
Member

@siddharthvp siddharthvp commented Oct 29, 2019

Largely addresses #6. Per #6 (comment), the server time is available to us whenever we are in a .load() callback, via the starttimestamp attribute in load API output which is stored in Morebits.wiki.page as ctx.loadTime, publicly exposed via .getLoadTime().

In case of RFD, the curtimestamp parameter is added to the API request while finding the target of the redirect, so that the server time is available while determining the log page.

The only remaining usages of client clock is in:

  • an3 - not important to fix as it is only used for deciding what revisions to retrieve from which user can select reverts.
  • in determining daily log page name for CFD, FFD and TFD. The code that does is sitting outside of any load callback, because unlike in AfD, tagging of the page is occurring after the discussion is posted. Maybe the order can be changed in a future Great XfD De-Duplication Project.

@siddharthvp
Copy link
Member Author

Note: the starttimestamp parameter in load API output is added by intoken=edit (it adds the token and this timestamp). If we remove that or replace that by meta=tokens in the future, the current timestamp will need to be explicitly requested using the curtimestamp param.

@Amorymeltzer
Copy link
Collaborator

I've yet to thoroughly review this, but it all looks very reasonable; I'm surprised we've gone so long without wanting getLoadTime!

Note: the starttimestamp parameter in load API output is added by intoken=edit (it adds the token and this timestamp). If we remove that or replace that by meta=tokens in the future, the current timestamp will need to be explicitly requested using the curtimestamp param.

Could you add a comment to this effect? #615 can be our open ticket, but a comment in the code would be nice. I'll try to get to this in the new year, sorry for the lag.

Copy link
Collaborator

@Amorymeltzer Amorymeltzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magnifique! Two requests for updated comments, but otherwise 💯

@@ -241,8 +241,7 @@ Twinkle.prod.callbacks = {

// Alert if article is at least three days old, not in Category:Living people, and BLPPROD is selected
if (params.blp) {
var now = new Date().toISOString();
var timeDiff = (new Date(now) - new Date(params.creation)) / 1000 / 60 / 60 / 24; // days from milliseconds
var timeDiff = (new Date(pageobj.getLoadTime()).getTime() - new Date(params.creation).getTime()) / 1000 / 60 / 60 / 24; // days from milliseconds
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Yes, much better!

@@ -1242,20 +1243,22 @@ Twinkle.xfd.callbacks = {
// This is a closure for the callback from the above API request, which gets the target of the redirect
findTargetCallback: function(callback) {
return function(apiobj) {
var xmlDoc = apiobj.responseXML;
var target = $(xmlDoc).find('redirects r').first().attr('to');
var $xmlDoc = $(apiobj.responseXML);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that elsewhere in xfd we don't use the jquery naming convention; this is the only one that actually uses it for more than convenience, so it's reasonable to do here.

modules/twinklexfd.js Outdated Show resolved Hide resolved
morebits.js Show resolved Hide resolved
Largely addresses wikimedia-gadgets#6. Per wikimedia-gadgets#6 (comment), the server time is available to us whenever we are in a `.load()` callback, via the starttimestamp attribute in load API output which is stored in Morebits.wiki.page as ctx.loadTime, publicly exposed via `.getLoadTime()`.
The curtimestamp parameter is added to the API request while finding the target of the redirect, so that the server time is available while determining the log page.
@siddharthvp
Copy link
Member Author

Looks like my git directory on windows has went bust (weird permission denied errors). Will push the latest changes when later when I log into ubuntu.

Copy link
Collaborator

@Amorymeltzer Amorymeltzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆

@Amorymeltzer Amorymeltzer merged commit 48e8ea6 into wikimedia-gadgets:master Jan 7, 2020
Amorymeltzer added a commit to Amorymeltzer/twinkle that referenced this pull request Feb 21, 2020
1. Since wikimedia-gadgets#741 (specifically, 3e21765), RfD was using a returned `curtimestamp` to generate the log page.  That query was only being done if the page wasn't a soft redirect, however, leading to NaN/undefined issues.  Closes wikimedia-gadgets#861 by falling back to the previous client clock method.
2. wikimedia-gadgets#527 (44c0e42) added the ability to notify a redirect's target, but returns an error if the title is invalid, such as with soft redirects via {{wi}}.  This now skips the notification in such cases.
Amorymeltzer added a commit to Amorymeltzer/twinkle that referenced this pull request Mar 14, 2020
…tokens

Deprecated ages ago (see https://www.mediawiki.org/wiki/MediaWiki_1.24#API_changes and https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/153110/).  Closes wikimedia-gadgets#615.

Use `curtimestamp` on `.load` calls now that we no longer use `intoken`.  As noted in wikimedia-gadgets#741, `starttimestamp` was only available because we were still using the outdated `intoken` method.  With that gone, we need to explicitly provide `query.curtimestamp`, thus replicating the loading timestamp that we can feed it into `starttimestamp` and avoid edit conflicts.  Also replaced `intoken` in `twinklefluff.js` and removed the undelete kludge from wikimedia-gadgets#616.  Some references to token names in error messages are kept for ease of debugging.
wiki-ST47 pushed a commit to wiki-ST47/twinkle that referenced this pull request Sep 2, 2020
1. Since wikimedia-gadgets#741 (specifically, 3e21765), RfD was using a returned `curtimestamp` to generate the log page.  That query was only being done if the page wasn't a soft redirect, however, leading to NaN/undefined issues.  Closes wikimedia-gadgets#861 by falling back to the previous client clock method.
2. wikimedia-gadgets#527 (44c0e42) added the ability to notify a redirect's target, but returns an error if the title is invalid, such as with soft redirects via {{wi}}.  This now skips the notification in such cases.
wiki-ST47 pushed a commit to wiki-ST47/twinkle that referenced this pull request Sep 2, 2020
…tokens

Deprecated ages ago (see https://www.mediawiki.org/wiki/MediaWiki_1.24#API_changes and https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/153110/).  Closes wikimedia-gadgets#615.

Use `curtimestamp` on `.load` calls now that we no longer use `intoken`.  As noted in wikimedia-gadgets#741, `starttimestamp` was only available because we were still using the outdated `intoken` method.  With that gone, we need to explicitly provide `query.curtimestamp`, thus replicating the loading timestamp that we can feed it into `starttimestamp` and avoid edit conflicts.  Also replaced `intoken` in `twinklefluff.js` and removed the undelete kludge from wikimedia-gadgets#616.  Some references to token names in error messages are kept for ease of debugging.
@siddharthvp siddharthvp deleted the noclientclock branch October 22, 2020 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants