Commit graph

3564 commits

Author SHA1 Message Date
Ankush Menat
bd3af4391f
fix: Commit ID parsing (#28975)
This is/was never returning anything.

- Arguments come before revs
- `cd` is kinda unnecessary
2024-12-31 10:33:57 +00:00
Ankush Menat
3788f30b5b
perf: reduce RQ Worker's polling frequency (#28957) 2024-12-30 14:37:00 +05:30
Ankush Menat
766cb64d55
perf!: Cache site configs in memory for 60 seconds (#28869)
This is middle ground between caching it completely and requiring a
restart/signal to reload vs always reloading it.

I don't know any use cases that can break from this, nowhere in code
configs should be expected to reload instantly.

This change is only applied to requests for now
2024-12-27 16:21:14 +00:00
Ankush Menat
28453f59f8
refactor: Flatten @site_cache's internal representation (#28939)
This makes maxsize deterministic while estimating memory costs of
using this function.

E.g. If I want to cache site config and I'd prefer to keep 16 recent
site configs in memory, there's no way to handle this. Site specific
maxsize means if I have 1000 sites on bench I'll have 1000 keys in
cache.

This change makes behaviour similar to lru_cache which is how I thought
it workerd TBH.
2024-12-27 15:50:07 +00:00
Ankush Menat
416919e880
Revert "feat: Use RESP3 for Redis cache connections (#28929)" (#28938)
This reverts commit 6f7b4c412e.
2024-12-27 13:19:35 +00:00
Ankush Menat
6f7b4c412e
feat: Use RESP3 for Redis cache connections (#28929)
RESP3 has PUSH support which is useful for implementing client side
caching. Enabling this before I work on that to test if anything breaks
with this.

No need to do this for background jobs instance just yet, infrequent
accesses and performance doesn't matter as much.
2024-12-27 06:15:59 +00:00
Akhil Narang
7af83f6d37
Merge remote-tracking branch 'upstream/develop' into invalid-encr-key-message
* upstream/develop: (1373 commits)
  perf: cache dynamic links map in Redis (#28878)
  fix: Never query `flag_print_sql` in `developer_mode=0` (#28884)
  fix(restore): remove MariaDB view security definers
  fix: sanitize user input during setup wizard
  feat(sanitize_column): improve check
  refactor: make optimizations.py private entirely (#28872)
  fix(site_cache): site cache thread safety (#28870)
  chore(printview): change error message
  perf: speedup `frappe.call` by ~8x (#28866)
  test: reduce noise in test output (#28862)
  chore: spelling_invalid_values (#28858)
  fix: Remove misleading os.O_NONBLOCK flag (#28859)
  fix: string replacement in error logger
  perf(gthread): Pin web workers to a single core (#28854)
  fix: MariaDBDatabase.get_tables() should not query the entire database schema (#28846)
  fix: add strings and fields to translation
  fix: typo in test controller boilerplate
  perf: faster add_to_date (#28843)
  perf(version): Make get_versions fast for autoincrement doctypes (#28847)
  refactor: log in monitor as well
  ...
2024-12-24 12:36:33 +05:30
Akhil Narang
6b9960ca5c
chore: update message
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-24 12:35:19 +05:30
Akhil Narang
105a3b153d
Merge pull request #28513 from akhilnarang/fix-retry-background-job-after-job-hook
fix(background_jobs): init site if required for after_job hooks
2024-12-24 11:38:32 +05:30
Akhil Narang
b5bad56cdd
feat(sanitize_column): improve check
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-23 16:16:08 +05:30
Akhil Narang
21a6d2a717
Merge pull request #28868 from akhilnarang/printview-cleanup-checks
chore(printview): change error message
2024-12-23 15:27:54 +05:30
Ankush Menat
17686eba3b
fix(site_cache): site cache thread safety (#28870)
Identified two cases where site cache can break:

1. Other thread clears cache using clear_cache because of TTL or manual
   eviction.
2. Other thread pops the eliment we are about to read because of
   `maxsize` limit.

This change should fix both and even make it lil bit faster.
2024-12-23 13:44:19 +05:30
Akhil Narang
5a4239fbe3
chore(printview): change error message
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-23 13:29:44 +05:30
Ankush Menat
f243aa1942
perf: faster add_to_date (#28843)
* fix(DX): Accept None directly as input to add_to_date

It's already supported, signature is just not updated.

* perf: use efficient date parser
2024-12-21 05:23:34 +00:00
Ankush Menat
9e9096834f
perf: pretty_date - avoid useless dt->string->dt cycle (#28842) 2024-12-19 14:53:38 +00:00
Ankush Menat
17cc356915
perf: speed up flt by 1.06x and get_system_settings by 1.32x (#28841)
* perf: resolve rounding method once

When rounding method is explcitly specified it's 1.4x faster.

* perf: reorder checks

Bankers rounding is default and most common now

* perf: speedup get_system_settings
2024-12-19 14:38:45 +00:00
Ankush Menat
1c2f8abb4e
perf: speedup get_datetime by ~9.5x (#28840) 2024-12-19 20:01:45 +05:30
Ankush Menat
9419344c76
fix: always print tracebacks (#28838)
* fix: fallback for always printing tracebacks

I don't recall ever hitting "no" to this prompt. It's of no use for me.

Also, this makes automated scripts not really automated.

* revert: prompting for exceptions

Always print full exception
2024-12-19 12:46:11 +00:00
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
7dd15e3613
perf: speedup pickling of document objects (#28823)
* perf: Use latest pickle protocol

* perf: pop flags from cached documents

This is also the right thing to do, things like `doc.flags.for_update`
shouldn't be "cached".
2024-12-18 10:18:04 +00:00
Ankush Menat
3297aff294 fix: Always set value in local even if it expires 2024-12-17 18:34:45 +05:30
Ankush Menat
b5218096e1 perf: reduce one redis call for redis_cache 2024-12-17 18:04:43 +05:30
Ankush Menat
d0c314090c
perf: speed up recurring redis cache accesses (#28805) 2024-12-17 14:06:01 +05:30
Ankush Menat
c1c4a7dd48
perf: speed up @request_cache by ~2x (#28803)
- Eagerly initialize request_cache, all requests use it, so what is the
  point of doing it lazily?
- Reduce accesses to `frappe.local` namespace, get cache once and reuse
  it in rest of the execution.

Before: 1250ns +/- 1%
After: 645ns +/- 1%

Source: Trust me bro.
(no really, for now just trust me or look at the diff)
2024-12-17 07:35:38 +00:00
Ankush Menat
9951f151f5 perf!: Drop support for unhashable arguments
Just like LRU cache, no need to support unhashable types in site_cache.
Current usage in codebase also shows that it's not required and json.dumps is quite slow.
2024-12-17 11:48:17 +05:30
Ankush Menat
f9ed28956d perf: use monotonic time instead of realtime for eviction
datetime is complex, slow and not really required for this use case.
2024-12-17 11:41:55 +05:30
Ankush Menat
3675f3c797 perf(site_cache): reduce access to frappe.local namespace
This change also allows calling @site_cache during init, as long as `site` parameter is set.
2024-12-17 11:23:51 +05:30
Akhil Narang
b95dba750a
fix(background_job): reset after_job CallbackManager before retrying a job
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-11 18:09:41 +05:30
Ankush Menat
2295d3108d
chore: make bench_helper executable (#28742)
I need a real entry point that isn't wrapped by bench CLI.
2024-12-11 10:52:58 +00:00
Akhil Narang
090d57d97b
fix(background_jobs): init site if required for after_job hooks
If a job has been retried, we'll enter the finally section after `frappe.destroy()` has been called

Additionally, only run these on the "original" call, not on each retry call

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-11 11:33:15 +05:30
Akhil Narang
4cf18d37bd
fix(convert_utc_to_timezone): set UTC if tzinfo undefined
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-10 16:12:01 +05:30
David Arnold
d17136cd04
fix: redirect cssutils logger to file (#28692) 2024-12-08 13:42:18 +05:30
David Arnold
3d71f594d8
refactor: bench class inauguration (#28158)
* feat: Add bench layout classes and configuration handler

Bench layout: (`frappe.bench`)

- Layout by env variable, e.g. FRAPPE_BENCH_PATH, FRAPPE_SITES_PATH, etc
- Detecting modules and apps by the presence of a sentinel .frappe file
- Site is scoped by frappe.local.site_name (thread safe)

Config handler: (`frappe.bench.sites{,.site}.config`)

- Optional config registry for better discovery; warning if not specced
- Env variable overload with `FRAPPE_` prefix

* chore: type frappe.config

* chore: type frappe.bencher

* chore: py310 compat
2024-12-06 19:07:34 +01:00
Akhil Narang
ad1ed62652
fix: handle ZoneInfoNotFoundError
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-06 16:01:43 +05:30
Gavin D'souza
00163f5bf4
fix: Re-define utils to match previous behaviour 2024-12-06 15:43:33 +05:30
Gavin D'souza
c6580b5880
refactor: Replace pytz to std lib zoneinfo & datetime
Signed-off-by: Gavin D'souza <gavin.dsouza@switchup.de>
2024-12-06 15:43:33 +05:30
David Arnold
75377aaaf5
refactor(typing): type filters (#28218)
* chore(typing): type filters

* chore(typing): type filters for get_list et al

* fix: dashboard chart filter expression

* test: fix case with new-style right hand object to equality check

* chore: place new typed filter under typing verification

* chore: remove debug print statment

* chore: inverse logic of type guard

* fix: add float to filter value types

* chore: clarify value naming
2024-12-04 23:18:53 +00:00
Akhil Narang
1a45cd3ab0
chore(cint): explicitly handle NoneTypes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 15:36:25 +05:30
Akhil Narang
9c9349b74f
Merge pull request #28658 from akhilnarang/flt-explicit-handle-nonetype
chore(flt): explicitly handle NoneTypes
2024-12-04 15:21:42 +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
Akhil Narang
cfeb1224e6
chore(flt): explicitly handle NoneTypes
These were implicitly handled due to the catch-all 0.0 return, but type checkers break here, and a lot of places depend on this behaviour

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 12:54:46 +05:30
David Arnold
e2a8c7fed3
test: fix universal type checker based on downstream use and more testing (#28619)
* test: fix universal type checker based on downstream use and more testing

* fix: type validation error reporting

* fix: types; various

* chore: switch off test-time type checking

still too many errors
2024-11-28 23:35:32 +01:00
David Arnold
9edd44de01
ci: this adds universal runtime typechecking during tests to test runners (#28554)
* ci: this adds universal runtime typechecking during tests to test runners

* ci: add configuration options for test-time type checking
2024-11-28 15:11:30 +00:00
David Arnold
a4014ab1c4
fix(json-serialization): prioritize explicit __json__ before iterable (#28597) 2024-11-27 13:11:53 +00:00
David Arnold
d8fab7a64f
chore: use deprecation dumpster for remaining deprecated decorator (#28555) 2024-11-23 23:50:56 +00:00
David Arnold
2f559e0fa9
chore: make the type clear (#28524) 2024-11-19 22:40:26 +00:00
David Arnold
223640d8a7
feat: render debug timer (#28501) 2024-11-18 12:59:23 +00:00
David Arnold
7065489759
fix: jinja template html errors (#28490) 2024-11-17 10:35:09 +00:00
David Arnold
67f2b056b4
feat: add hook to allow downstream apps to add auto-loading instrumentation for their doctypes (#28479) 2024-11-15 13:04:20 +00:00
Abdeali Chharchhoda
066f7c66de fix: add summary html element to acceptable_elements 2024-11-15 16:54:18 +05:30