Skip to content

Relative timestamps#31

Merged
Alexia merged 2 commits intoAlexia:masterfrom
cotto:relative-timestamps
Mar 13, 2017
Merged

Relative timestamps#31
Alexia merged 2 commits intoAlexia:masterfrom
cotto:relative-timestamps

Conversation

@cotto
Copy link

@cotto cotto commented Mar 9, 2017

DPL3 doesn't currently have a way to filter revisions relative to the current time (e.g. "get me all revisions in the last hour"). This patch provides one way to implement that feature.

My motivation is that I'd like to build a list of the most recent 10 edits via DPL. This list needs to be regenerated every time it's viewed (allowcachedresults=false) and it will be on our front page, so performance is important. It would technically be possible to use allrevisionsbefore=2017-03-01|count=10 but that will gradually slow down unless the allrevisionsbefore date is updated manually. With this patch, it's possible to create a list of the most recent edits that will always be efficient.

The patch adds the following timestamps: today, last hour, last day, last week, last month, last year. They're converted into numeric timestamps before being passed to the database.

I'm not married to the current format (e.g. allrevisionssince=last day). I toyed around with the syntax and this seems to be the cleanest. It'd also be possible to expose the value passed to DateInterval directly (e.g. allrevisionssince=P1M3D2H for 1 month, 3 days and 2 hours) but that's less friendly and exposes implementation details. Suggestions are welcome.

@Alexia, I've also got an all-fixes branch in my clone which contains all 3 changes (revision filter efficiency, sort direction and this change) if you want to merge everything in one shot. There's a minor (and easily-resolved) merge conflict that you'll run into if you merge them one-by-one.

Christoph Otto added 2 commits March 8, 2017 15:01
The underlying column is a string and MySQL's optimizer does much better
when comparing strings to strings.
@Alexia
Copy link
Owner

Alexia commented Mar 13, 2017

No issues with this patch. I am going to make one super minor improvement with a strtolower() on the input for user friendliness, but that is it.

@cotto
Copy link
Author

cotto commented Mar 13, 2017

Good idea. Thanks for the merge!

@cotto cotto deleted the relative-timestamps branch March 13, 2017 19:37
@Alexia
Copy link
Owner

Alexia commented Mar 13, 2017

Thank you for contributing. I appreciate it! I hate being so busy that I can sometimes barely come around to look at pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants