Commit Graph

21 Commits

Author SHA1 Message Date
Nicolas F 5c943f35e3 Add login endpoint rate limiting
This doesn't discriminate between failed logins and successful
logins, but only counts POST requests. The limit is set to 6 per
hour.
2020-06-23 00:49:26 +02:00
Nicolas F 80c9d580eb Improve cache configuration (#564)
The Flask-Caching cache can now properly be configured from the
config.py, and redis caching has experimentally been tested and
confirmed to be working in theory.

We also document that one may want to use CACHE_THRESHOLD to limit
the maximum number of items in the simple cache.
2019-08-10 18:53:57 -07:00
TheAMM 885cccca40 Cache url_for calls with lru_cache
This commit adds a caching_url_for using functools.lru_cache (currently
with maxsize at 4096 entries) and replaces flask.url_for with it, as
there is no harm in doing so.

This greatly improves template generation speed, from ~115ms to ~75ms on
the front page (using the simple benchmark introduced in the previous
commit).
2019-04-08 19:28:26 +02:00
TheAMM b0c51e9fa0 Add very simple benchmarking support when debugging 2019-04-08 19:31:34 +03:00
Nicolas F bd419c5d39 Add 1 hour cache to magnet URIs (#503)
Using Flask-Caching, we can memoize the magnet_uri method. Here, a
timeout of 1 hour is chosen, though that value can be fiddled with.

The cache is defined in extensions.py, but gets initialised in
__init__.py.
2018-07-10 01:22:49 -07:00
Nicolas F 56a670977e [Config Change] Various Gravatar-related changes (#467)
* Add config option to enable/disable gravatar

This is useful when running a development instance behind a firewall
or NAT, where gravatar cannot reach you to serve up the default user
avatar.

* Pregenerate Gravatar default image URLs

If possible (i.e. SERVER_NAME is set), we can pregenerate the constant
gravatar default URL once at application startup, and re-use that,
as url_for calls are surprisingly expensive.

Especially on torrent view pages with lots of comments, this cuts down
on url_for calls massively, saving on my system about 0.3 ms per call.
2018-07-09 22:20:26 -07:00
Nicolas F 291f859a4f Use Flask-Assets to minify self-hosted JS files (#468)
* Use Flask-Assets to minify self-hosted JS files

By having Flask-Assets minify the two JS files we ship, namely
main.js and bootstrap-select.js, we can shave off 28406 bytes.

The minified files are generated on startup. If one wishes to
manually clean them up or build them, they can use the
"flask assets" management command, e.g. "flask assets clean".

* Workaround to fix tests

State carries over in tests, which is the dumbest shit ever. Fix it
by clearing the bundles before setting them.
2018-04-04 16:02:05 +02:00
TheAMM 6b49af4fb7 Exception handling: include a random string to identify stacks from log 2017-09-02 22:18:32 +03:00
Kfir Hadas a758f5f078 Optimize routes (define url_prefix in Blueprints)
* /admin/*
* /api/*
2017-08-15 17:12:54 +03:00
TheAMM 7a04d64f9c Weed out last few hardcoded urls 2017-08-05 22:43:13 +03:00
Kfir Hadas 87dd95f1e0 Refactor into an app factory [2 of 2] (#322)
* Replace all `from nyaa import app` imports with `app = flask.current_app` (or `from flask import current_app as app` where possible)
* Add a separate config object for top-level and class statements as `nyaa.extensions.config`
Required because those codes don't have app context at the time of evaluation/execution.
* Remove `routes.py` file and register all blueprints in `nyaa/__init__.py`
* Refactor `nyaa/__init__.py` into an app factory
* Update tools
* Update tests (temporary, will be replaced)
2017-08-01 21:02:08 +03:00
Kfir Hadas 0181d6cb33 Prepare for app factory [1 of 2] (#315)
* Move db, assets, debug toolbar and fix_paginate into nyaa.extensions
* Change all `from nyaa import db` imports to `from nyaa.extensions import db`
* Move `nyaa.torrents.create_magnet_from_es_info` context processor into template-utils blueprint
* Fix tools (wrap in `with app.app_context():` where needed)
2017-07-30 20:35:16 +03:00
Kfir Hadas b992467dad Apply isort & flake8 (#312)
* Update isort settings
* Apply import sorting (isort) on all files in nyaa/
* Fixed Flake8 errors in nyaa/ (see PR for list)
* Add isort to lint.sh and requirements.txt
2017-07-28 20:01:19 +03:00
Kfir Hadas 16e72a2a9c set noqa to ignore a single error 2017-06-08 04:14:04 +03:00
TheAMM 260dc2cdc8 Forbid caching when debugging 2017-05-27 21:33:20 +03:00
nyaadev 76812b0ef0 utf8mb4 for database connection 2017-05-23 00:46:26 +02:00
katnyaa 1016d5be02 Fix typo 2017-05-22 13:02:02 +00:00
sharkykh 571b7f2930 Ignore routes import line 2017-05-16 12:43:33 +03:00
sharkykh 2a71fd8158 Display the site's commit hash 2017-05-14 12:02:39 +03:00
nyaadev 064c33ecf4 Fix cookies messing with cache
Change Display name to Torrent display name for clarity
2017-05-13 19:26:43 +02:00
nyaadev 00d65e312c Initial commit. 2017-05-12 20:51:49 +02:00