Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
insights
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
insights
Commits
5cd7b5c2
Commit
5cd7b5c2
authored
Mar 29, 2013
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better isuseful
parent
e8bcec7f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
src/djanalytics/decorators.py
+8
-6
No files found.
src/djanalytics/decorators.py
View file @
5cd7b5c2
...
@@ -100,14 +100,16 @@ def query(category = None, name = None, description = None, args = None):
...
@@ -100,14 +100,16 @@ def query(category = None, name = None, description = None, args = None):
import
hashlib
import
hashlib
import
json
import
json
def
isuseful
(
a
):
def
memoize_query
(
cache_time
=
60
*
4
,
timeout
=
60
*
15
,
ignores
=
[
"<class 'pymongo.database.Database'>"
,
"<class 'fs.osfs.OSFS'>"
]):
if
str
(
type
(
a
))
in
[
"<class 'pymongo.database.Database'>"
,
"<class 'fs.osfs.OSFS'>"
]:
''' Call function only if we do not have the results for its execution already
We ignore parameters of type pymongo.database.Database and fs.osfs.OSFS. These
will be different per call, but function identically.
'''
def
isuseful
(
a
,
ignores
):
if
str
(
type
(
a
))
in
ignores
:
return
False
return
False
return
True
return
True
def
memoize_query
(
cache_time
=
60
*
4
,
timeout
=
60
*
15
):
''' Call function only if we do not have the results for it's execution already
'''
def
view_factory
(
f
):
def
view_factory
(
f
):
def
wrap_function
(
f
,
*
args
,
**
kwargs
):
def
wrap_function
(
f
,
*
args
,
**
kwargs
):
# Assumption: dict gets dumped in same order
# Assumption: dict gets dumped in same order
...
@@ -119,7 +121,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15):
...
@@ -119,7 +121,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15):
s
=
str
({
'uniquifier'
:
'anevt.memoize'
,
s
=
str
({
'uniquifier'
:
'anevt.memoize'
,
'name'
:
f
.
__name__
,
'name'
:
f
.
__name__
,
'module'
:
f
.
__module__
,
'module'
:
f
.
__module__
,
'args'
:
[
a
for
a
in
args
if
isuseful
(
a
)],
'args'
:
[
a
for
a
in
args
if
isuseful
(
a
,
ignores
)],
'kwargs'
:
kwargs
})
'kwargs'
:
kwargs
})
m
.
update
(
s
)
m
.
update
(
s
)
key
=
m
.
hexdigest
()
key
=
m
.
hexdigest
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment