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

Generalised caching, more documentation, and other set-up things #29

Merged
merged 10 commits into from Oct 24, 2016
Merged

Generalised caching, more documentation, and other set-up things #29

merged 10 commits into from Oct 24, 2016

Conversation

samwilson
Copy link
Member

@samwilson samwilson commented Oct 13, 2016

This change adds a PSR-6 compatible caching system, instead of
only using Redis. This makes it easier to run locally (without
installing Redis).

Also extends the local-development setup instructions, making it
clearer what needs to be done to get things
up and running. Composer will now create a default .env file.

The Less cache is moved to the top-level 'cache' directory, because
this is where the cache is when Redis isn't used and because /src
seems like an odd place for volatile files. The new cache directory is added to the repo (empty) and a note about making it writable added to the readme.

The /login route is removed because it wasn't used anyway.

composer.lock is added, because then composer install will install the same thing for everyone, and the same in production (where composer update should never be run).

Copy link
Member

@MusikAnimal MusikAnimal left a comment

Choose a reason for hiding this comment

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

Big improvements! Left a few comments then also, in the super cool composer script, we should create the cache directory. Alternatively you could maybe add a .gitkeep file in /cache, then in .gitignore ignore everything in /cache except that file.

Another big thing that should have been in the README, we have to make the cache directory server-writable, which I think might involve a chmod 777

```
$ mysqldump -u LABSYOU -p -P 4711 -h 127.0.0.1 --skip-lock-tables s51306__copyright_p > copyright.sql
$ mysql -u LOCALYOU -p -e "CREATE DATABASE copypatrol_dev;"
$ mysql -u LOCALYOU -p copypatrol_dev < copyright.sql
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend connecting to the live copyright database through the same SSH tunnel, so in your .env you could use DB_DSN_PLAGIABOT = 'mysql:host=127.0.0.1;dbname=s51306__copyright_p;port=4711'

This way you don't need to recreate the data locally

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about that, but doesn't it need to update it also? Perhaps I've read things wrongly... if so, then yeah definitely no need to recreate locally! :-) Much easier.

Copy link
Member

Choose a reason for hiding this comment

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

The s51306__copyright_p table is what's being continually updated by EranBot, so you'll have a continuous flow of new data, at least until people stop adding copyright violations :) It is true our users go through the backlog pretty quickly, so if you wanted to test something against a lot of unreviewed cases you probably won't be able to. For most dev work I don't think this will be a problem, though

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, sounds good. I'm changing .env_example. Can a similar thing be done for the wikiproject database?

Copy link
Member

Choose a reason for hiding this comment

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

Goes to show how bad we've done with documentation over the course of development... the wikiproject database is no longer being used! So we can remove it entirely

Copy link
Member Author

Choose a reason for hiding this comment

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

ha! no worries. :-)

],
"post-update-cmd": [
"php -r \"file_exists('.env') || copy('.env_example', '.env');\""
]
Copy link
Member

Choose a reason for hiding this comment

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

super cool!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, just a shame that there's no post-update-or-install-cmd! :-)

}
$cache->setDriver( $driver );
return $cache;
} );
Copy link
Member

Choose a reason for hiding this comment

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

This is awesome! No disadvantage to having a local cache, but you could also make it work off the remote Redis via SSH tunnel ssh -L 4711:enwiki.labsdb:3306 -L 4712:tools-redis:6379 YOU@tools-dev.wmflabs.org then adjust .env accordingly. I should have added that to the README some time ago

This change adds a PSR-6 compatible caching system, instead of
only using Redis. This makes it easier to run locally (without
installing Redis).

Also extends the local-development setup instructions, perhaps too
verbosely, making it clearer what needs to be done to get things
up and running. Composer will now create a default .env file.

The Less cache is moved to the top-level 'cache' directory, becuase
this is where the cache is when Redis isn't used and because /src
seems like an odd place for volatile files.

The /login route is removed because it wasn't used anyway.
Remove the notes about having a local database, add the cache
directory (but not its contents), and add the composer.lock
file so that everyone gets the same dependencies.
@MusikAnimal
Copy link
Member

I'm not convinced the tests are working on Travis, unless it really takes 4+ hours... they pass locally so you've got my 👍. Might need another set of eyes? Not sure

@samwilson
Copy link
Member Author

Yeah it's very strange. They took half an hour or so earlier, but reported themselves as 5 minutes or something.

I think the others should look at this first though. Just in case.

@samwilson
Copy link
Member Author

Travis must've just been busy doing other things; ey got it to eventually.

@samwilson
Copy link
Member Author

@Niharika29 would you mind casting your eye over this PR? Thanks!


; Caching system. If a Redis host is not defined, a local Filesystem cache will be used instead.
REDIS_HOST = "tools-redis"
REDIS_PORT = 6379
Copy link
Member

Choose a reason for hiding this comment

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

We might want to add SLIM_MODE = 'development' here, or at least I have on my local. Looking at the core Slim code I'm not convinced this does anything in particular by itself, but we might (or should) use it in other parts of the app, e.g. https://github.com/wikimedia/CopyPatrol/blob/master/src/Controllers/CopyPatrol.php#L364

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. At the moment we're determining staging with $slim->view->set( 'staging', strpos( $rootUri, 'plagiabot' ) ); which could maybe be changed to a mode member of the container that uses SLIM_MODE (or APP_ENV? That seems a common name in some PHHP circles...).

And there's LOG_LEVEL and LOG_FILE too, which are good to set for development, to maybe include in this file.

OAUTH_SECRET_TOKEN =
OAUTH_ENDPOINT = 'https://meta.wikimedia.org/w/index.php?title=Special:OAuth'
OAUTH_REDIR = 'https://meta.wikimedia.org/wiki/Special:OAuth/authenticate?'
OAUTH_CALLBACK = 'oob'
Copy link
Member

Choose a reason for hiding this comment

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

what is oob?

Copy link
Member Author

Choose a reason for hiding this comment

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

'Out Of Band', which isn't really correct because we do actually use a callback. (OOB usually means e.g. a desktop application is requesting the auth.) In our case, the callback is fixed by the consumer registration on Meta, so actually this will be ignored; it does have to be something though.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Yeah for us it looks like we need a full URL to /copypatrol/oauth/callback. On my local I have the app running at localhost/copypatrol so I use http://localhost/copypatrol/oauth/callback and this works. We might suggest something similar here

@MusikAnimal
Copy link
Member

FYI I've got this branch up and running on our staging environment and all seems well :) https://tools.wmflabs.org/plagiabot

Copy link
Collaborator

@kaldari kaldari left a comment

Choose a reason for hiding this comment

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

Everything looks awesome to me. Just had one question (see inline).

@@ -1,11 +1,13 @@
{
"license": "GPL-3.0+",
"require": {
"ext-intl": "*",
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do we need the intl extension for?

Copy link
Member

Choose a reason for hiding this comment

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

That's for the number formatting I think. I did not know we could require PHP extensions through composer, so I ended up manually installing/enabling it my php.ini

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's for NumberFormatter. Composer can't install extensions but it does alert people to the fact that they are required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of requiring intl (which might require someone to spend half an hour upgrading their PHP), let's just check for the existence of NumberFormatter. After all, number formatting isn't critical to the tool's functionality:

if ( class_exists( 'NumberFormatter' ) ) {
    $formatter = new \NumberFormatter( $locale, \NumberFormatter::DECIMAL );
    // Get separator symbols (include decimal as it is required and we might use it at some point)
    $decimal = $formatter->getSymbol( \NumberFormatter::DECIMAL_SEPARATOR_SYMBOL );
    $thousands = $formatter->getSymbol( \NumberFormatter::GROUPING_SEPARATOR_SYMBOL );
} else {
    $decimal = '.';
    $thousands = ',';
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! And we can make it simpler even, because the Twig defaults are the same as you've set there (dot and comma).

@samwilson samwilson closed this Oct 22, 2016
@samwilson samwilson reopened this Oct 22, 2016
@samwilson
Copy link
Member Author

I closed and opened this earlier because the Github Android app is rubbish. :-)

@@ -179,6 +199,10 @@ protected function configureRoutes( \Slim\Slim $slim ) {
}
},
'twig-number-format' => function () use ( $slim ) {
if ( class_exists( \NumberFormatter::class ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

!class_exists

Copy link
Member Author

Choose a reason for hiding this comment

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

Erk! Yes, well, hmm.... what can I say!?

:-)

(fixed now)

@MusikAnimal MusikAnimal merged commit 6bd1969 into wikimedia:master Oct 24, 2016
@samwilson
Copy link
Member Author

Yes, it's for NumberFormatter. Composer can't inatall extensions but itdoes alert prople to their requirement.

Sent from my field telephone with K-9 Mail. Please excuse brevity.

On 22 October 2016 11:22:53 am AWST, MusikAnimal notifications@github.com wrote:

MusikAnimal commented on this pull request.

@@ -1,11 +1,13 @@
{
"license": "GPL-3.0+",
"require": {

  • "ext-intl": "*",

That's for the number formatting I think. I did not know we could
require PHP extensions through composer, so I ended up manually
installing/enabling it my php.ini

You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants