-
Notifications
You must be signed in to change notification settings - Fork 68
[IMP] util/pg: cache column_exists for common columns #285
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
base: master
Are you sure you want to change the base?
[IMP] util/pg: cache column_exists for common columns #285
Conversation
upgradeci retry with always hr* _hr |
4d381c4
to
aff56cc
Compare
src/util/pg.py
Outdated
def _forced_cache(cache): | ||
def decorator(f): | ||
@functools.wraps(f) | ||
def wrapper(cr, *args, **kwargs): | ||
if not kwargs and tuple(args) in cache: | ||
return cache[tuple(args)] | ||
return f(cr, *args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator | ||
|
||
|
||
@_forced_cache(_COLUMNS) |
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 don't think the decorator is needed. It can be inline into the function directly.
def column_exists(cr, table, column):
if (table, column) in _COLUMNS:
return _COLUMNS[(table, column)]
return _column_info(cr, table, column) is not None
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.
Well, originally I was using it in get_value_or_en_translation
. It proved not as useful. I'm still working on this, I will simplify as much as possible before the final version. There are still some other columns being checked more than 70 times in the local test I'm doing.
|
In many cases we know that columns must exist, it's better to cache them to avoid thousands of small queries.
aff56cc
to
66473d6
Compare
In many cases we know that columns must exist, it's better to cache them
to avoid thousands of small queries.