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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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');\"" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super cool!
There was a problem hiding this comment.
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; | ||
} ); |
There was a problem hiding this comment.
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.
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 |
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. |
Travis must've just been busy doing other things; ey got it to eventually. |
@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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is oob
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
FYI I've got this branch up and running on our staging environment and all seems well :) https://tools.wmflabs.org/plagiabot |
There was a problem hiding this 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": "*", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = ',';
}
There was a problem hiding this comment.
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).
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 ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!class_exists
There was a problem hiding this comment.
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)
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:
|
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 thencomposer install
will install the same thing for everyone, and the same in production (wherecomposer update
should never be run).