Commit graph

246 commits

Author SHA1 Message Date
Ankush Menat
153c38571f fix: Never use HTTP cache in developer mode 2025-01-24 18:58:39 +05:30
Ankush Menat
32054b0757 refactor: use response_headers to set cache control headers 2025-01-24 18:35:26 +05:30
Ankush Menat
f30159adc6 feat: custom response header support 2025-01-24 18:35:26 +05:30
Ankush Menat
33d6ea94b8 fix: update instead of extend
None of these are supposed to be extended over defaults.
2025-01-24 18:35:26 +05:30
Ankush Menat
320798d390
perf: add cache-control headers on private files (#29221)
* perf: add cache-control headers on private files

- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with https://github.com/frappe/agent/pull/157

* fix: Don't override existing headers
2025-01-17 18:51:34 +05:30
Ankush Menat
430c0c7c7a
fix(DX): Log all exceptions in developer mode (#29195)
ALL exceptions - even validation errors. This is excessive logging but
in development mode it should be fine and even helpful in debugging few
issues.
2025-01-16 15:50:56 +05:30
Ankush Menat
9e8ab92371
refactor: move all optimizations and pre/post fork hooks to separate file (#28832)
Now they will truly execute before/after fork = :pinch: few bytes saved!
2024-12-19 16:46:26 +05:30
Ankush Menat
9d9193800b
fix: Keep HTTP caches private by default (#28719)
Developers can easily enable `can_cache` without knowing what it
entails. Public cache means proxy can likely cache things without
talking to backend.

Obviously many endpoints which can be cached on client side should
probably not be cached in proxy.

E.g. linked PR to the PR that added this feature suggest caching
notification log for short time... we don't want to leak one user's
cached notification to another user.

I don't buy that developers should know about cache implementation to
ensure it's secure or correct to enable it on certain endpoint. In
addition to that, we have very few mechanisms to burst cache
inside proxy. End user hitting ctrl+shift+r won't do anything if proxy
wants to serve stale response.

We should figure out better way to instruct FW about final cache
control headers than hardcoding it IMO.
2024-12-18 14:57:51 +05:30
Akhil Narang
84ef6ec677
refactor: fixup with ruff 0.8.1
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 13:18:04 +05:30
David Arnold
7e0f281fda
fix: revert etag implementation (#28358) 2024-11-03 11:02:29 +00:00
Rushabh Mehta
6da9d2a808
Merge pull request #28271 from rmehta/fix-oauth-page
fix(style): fix oauth authorisation page and standardise error responses
2024-11-03 10:42:04 +05:30
Gavin D'souza
ecb4795ed3
feat: Enable Sentry Sampling
Closes https://github.com/frappe/frappe/issues/28245
2024-10-28 11:27:51 +01:00
Rushabh Mehta
cef8c12ee4 fix(style): fix oauth authorisation page and standardise error responses 2024-10-24 15:21:34 +05:30
David Arnold
8cfeb156df
devx: add deprecation dumpster (#27887)
* feat: Add deprecation_dumpster.py file

* docs: add jovial and jocose docstring for frappe/deprecation_dumpster.py

* refactor: fill the dumpster with its own kind

* refactor: move to the deprecation dumpster

* chore: color coding class

* fix: only check import error when import errors
2024-10-08 18:56:10 +02:00
David
d87b786687
chore: fix all invocation of init for singledispatch -> min 1 positional arg 2024-09-13 11:53:52 +02:00
David
1619cc0e58
feat: add cache control 2024-08-30 09:08:42 +02:00
Ankush Menat
04642edd63
fix: Move Monitor dump to after_response (#26703)
It needs access to response to capture status code and size etc
2024-06-06 14:38:22 +00:00
Ankush Menat
445e1dbd6b
perf: num2words, babel, gettext, sentry imports (#26475)
num2words - 260KB - Used frequently on ERPNext sites.
babel - 1.1MB Gets imported because of dates, localization
sentry - 2.8MB should be loaded only if envvar is set
gettext - required for reading translations
2024-05-18 07:20:41 +00:00
Ankush Menat
7fe9cc4f09
perf: Don't update session in cache after every request (#26308)
It's just reading and writing same information except last_update inside
data which is never read back from this.
2024-05-04 06:10:38 +00:00
Ankush Menat
acf398f46e
fix: commit regardless of framework's transaction_writes count (#25322)
- There is code that depends on "commit", everything that happens with `db.after_commit`.
- There are operations that will not write anything to DB but just
  enqueue the function, if it's enqueue_after_commit then it will break.
2024-03-11 15:18:38 +05:30
Ankush Menat
bb7c3c289c
feat: support array request type (#25109)
There can be external APIs like webhooks that only send array request,
in which case Frappe has no mechanism to accept such requests.

After this PR such request data can be accessed using `data` list
argument on function.

I've considered directly storing list in form_dict but it's not
feasible:
1. It breaks semantics, "form_dict" can't be a list. That ship has long
   sailed.
2. Way too much code expects form_dict to be a dict.
2024-02-27 16:41:33 +00:00
Akhil Narang
3f1e19de85
refactor(treewide): enable RUF rules
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-21 16:20:28 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Akhil Narang
067104ca9c
refactor(sentry): sync up with FC implementation
Co-authored-by: Aditya Hase <aditya@adityahase.com>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2023-12-26 12:30:10 +05:30
Ankush Menat
52686f79cb refactor: code cleanup
- better boot config name
- send sentry after - because frappe namespce doesn't exist if it starts
  first
- remove import in app.py because __init__ is always imported so no
  need.
- leave telemetry JS always present, this is used even when telemetry is
  not enabled.
2023-11-30 17:40:53 +05:30
Akhil Narang
9a0a5468c5 feat: setup sentry integration
Inspired primarily from sentry's generic WSGI integration

Environment variable `FRAPPE_SENTRY_DSN` needs to be enabled as well
as explicit opt-in from the user's side in system sid telemetry
settings

Conditionally include telemetry JS bundles

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2023-11-30 17:13:41 +05:30
Ankush Menat
28d05c41c3 fix: correct max file size in boot 2023-11-22 10:55:52 +05:30
Maharshi Patel
5af9b294f5 fix: honour max file size in upload file
In case path is /api/method/upload_file, we should honour the max file size
set in system settings and set request max_content_length to that value.
2023-11-21 16:36:57 +05:30
Ankush Menat
284649d4f2 fix: Use werkzeug to identify JSON requests
We were excluding flavoured JSON like `application/vnd.xxx+json` which
can be parsed as JSON.
2023-11-07 17:28:33 +05:30
Ankush Menat
507343f4f6 fix: double response processing 2023-10-16 18:12:53 +05:30
Ankush Menat
e0f87dc4e1 refactor!: move OAuth and token auth code to auth.py
This doesn't belong in api.py
2023-10-16 18:12:53 +05:30
Ankush Menat
5af6624cce refactor: Use werkzeug router for API routing 2023-10-16 18:12:53 +05:30
Ankush Menat
c7338f5a83 chore: deprecate form_dict.cmd, globals() 2023-10-16 18:12:53 +05:30
barredterra
ed2290d1d6 Merge branch 'develop' into feat/improve-openid-connect-devx 2023-10-07 15:22:59 +02:00
Ankush Menat
56371f09e0 Revert "fix!: Bind development server only to localhost (#22397)"
This reverts commit 9244140816.

Breaks docker development installs
2023-09-20 11:43:56 +05:30
David Arnold
64a09be958
Merge branch 'develop' into feat/improve-openid-connect-devx 2023-09-16 09:58:53 +02:00
Ankush Menat
530c47ffe5
feat: after_response callback manager (#22398)
* feat: `after_response` callback manager

* perf: defer closing DB connection

* refactor: simplify after response hooks

* wip

* example usage

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>

* fix: Log request end if not already

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>
2023-09-14 10:56:08 +00:00
Ankush Menat
9244140816
fix!: Bind development server only to localhost (#22397) 2023-09-13 17:26:19 +05:30
0xsaif
aa7ee1c6b9
refactor: force ipv4 localhost (#22394)
* reafctor: force ipv4 localhost

Replacing "localhost" with "127.0.0.1" in the codebase; sometimes the name localhost force-resolves to ipv6

* revert: leave localhost usage in oauth tests

Change not required.

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-09-13 16:23:23 +05:30
Ankush Menat
4a5e584ad0
refactor: escape instead of sanitizing HTML (#22339)
Traceback if it contains HTML can be useful, better to escape and show
instead of modifying it.
2023-09-10 09:43:47 +00:00
David Arnold
87684e2647
feat: add werkzeug proxyfix to development server 2023-09-07 01:30:25 +02:00
Ankush Menat
07ff74edc5
feat: send unique request id as response header (#22218) 2023-08-28 13:19:34 +05:30
Ankush Menat
48f72655ad
feat(dx): Run gunicorn in development setup (#22088)
This lets developer run gunicorn in development setup while still being
able to use statics/assets.

While this is not "first class" support, it's usable for me. I don't see
need for more right now. Making this default in developer mode isn't
ideal IMO as it's quite heavy compared to werkzeug (and no debugger or
decent request logging)

To use in development mode swap `bench serve` with gunicorn command,
refer gunicorn config docs for more info.

```diff
- web: bench serve --port 8000
+ unicorn: gunicorn -b 127.0.0.1:8000 -w 1 --chdir /home/user/benches/develop/sites 'frappe.app:application_with_statics()' --preload
```

`no-docs`
2023-08-17 11:34:45 +05:30
gavin
6cb51a536e
fix: re module cache settings - purge & cache size (#21808)
* fix: Remove re cache internals manipulation

* fix: Purge re cache after module loads

Empty cache would work better as we already got our pre-compiled
patterns at the top level of every module. This leaves the cache open
for dynamically generated patterns which are in better need of it. Over
time, workers would converge to this anyway. This change only reduces
the cache hit and eviction effort.

I'd improve this by executing `re.purge` on every module import but
complexity tradeoff lol. I'd prefer if re didn't cache patterns
generated by `re.compile` but I dont see this behaviour or any escape
hatches so this will have to do for now.
2023-07-27 10:40:50 +05:30
Ankush Menat
3f142c1dce fix: respect system setting for tracebacks
closes https://github.com/frappe/frappe/issues/19826
2023-07-16 19:18:16 +05:30
Ankush Menat
d7990368a8
perf: preload more modules (#21557)
* perf: preload more modules

- bleach is used frequently for sanitization
- File gets imported anytime a private file is viewed. Indirect import
  of PIL is costly in each worker.

* test: warm up perf test
2023-07-02 21:47:21 +05:30
Ankush Menat
265a28e151 perf: preload pydantic 2023-07-02 16:32:40 +05:30
Ankush Menat
b9f000e1f9 refactor!: Log 5xx error to error log instead of error snapshot
Also move log_error function to right location
2023-06-28 10:59:19 +05:30
Ankush Menat
af03b76c88 perf: Preload and share common python modules 2023-06-24 21:24:02 +05:30
Ankush Menat
150c36c74d fix: collect before freezing 2023-06-24 17:36:10 +05:30