Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
0b2cabdd
Commit
0b2cabdd
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Working on cache problem #176
parent
1f883dc5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cutecoin/core/net/api/bma/access.py
+27
-43
27 additions, 43 deletions
src/cutecoin/core/net/api/bma/access.py
src/cutecoin/core/registry/identity.py
+2
-1
2 additions, 1 deletion
src/cutecoin/core/registry/identity.py
with
29 additions
and
44 deletions
src/cutecoin/core/net/api/bma/access.py
+
27
−
43
View file @
0b2cabdd
...
@@ -8,6 +8,7 @@ import json
...
@@ -8,6 +8,7 @@ import json
import
asyncio
import
asyncio
import
random
import
random
class
BmaAccess
(
QObject
):
class
BmaAccess
(
QObject
):
"""
"""
This class is used to access BMA API.
This class is used to access BMA API.
...
@@ -84,40 +85,14 @@ class BmaAccess(QObject):
...
@@ -84,40 +85,14 @@ class BmaAccess(QObject):
:return: True if the json dicts are the same
:return: True if the json dicts are the same
:rtype: bool
:rtype: bool
"""
"""
if
first
is
not
None
:
def
ordered
(
obj
):
if
not
isinstance
(
first
,
type
(
second
)):
if
isinstance
(
obj
,
dict
):
return
False
return
sorted
((
k
,
ordered
(
v
))
for
k
,
v
in
obj
.
items
())
if
isinstance
(
first
,
dict
):
if
isinstance
(
obj
,
list
):
for
key
in
first
:
return
sorted
(
ordered
(
x
)
for
x
in
obj
)
if
isinstance
(
second
,
dict
):
if
key
in
second
:
sec
=
second
[
key
]
else
:
# there are key in the first, that is not presented in the second
return
False
# recursive call
return
self
.
_compare_json
(
first
[
key
],
sec
)
else
:
# second is not dict
return
False
# if object is list, loop over it and check.
elif
isinstance
(
first
,
list
):
for
(
index
,
item
)
in
enumerate
(
first
):
# try to get the same index from second
sec
=
None
if
second
is
not
None
:
try
:
sec
=
second
[
index
]
except
(
IndexError
,
KeyError
):
# goes to difference
return
False
# recursive call
return
self
.
_compare_json
(
first
[
index
],
sec
)
# not list, not dict. check for equality
elif
first
!=
second
:
return
False
else
:
else
:
return
True
return
obj
return
ordered
(
first
)
==
ordered
(
second
)
def
_get_from_cache
(
self
,
request
,
req_args
,
get_args
):
def
_get_from_cache
(
self
,
request
,
req_args
,
get_args
):
"""
"""
...
@@ -126,17 +101,22 @@ class BmaAccess(QObject):
...
@@ -126,17 +101,22 @@ class BmaAccess(QObject):
:param cache_key: The key
:param cache_key: The key
:return:
:return:
"""
"""
if
request
==
blockchain
.
UD
:
pass
cache_key
=
BmaAccess
.
_gen_cache_key
(
request
,
req_args
,
get_args
)
cache_key
=
BmaAccess
.
_gen_cache_key
(
request
,
req_args
,
get_args
)
if
cache_key
in
self
.
_data
.
keys
():
if
cache_key
in
self
.
_data
.
keys
():
cached_data
=
self
.
_data
[
cache_key
]
cached_data
=
self
.
_data
[
cache_key
]
need_reload
=
False
need_reload
=
False
if
'
metadata
'
in
cached_data
:
if
'
metadata
'
in
cached_data
:
if
str
(
request
)
not
in
BmaAccess
.
__saved_requests
\
if
'
block
'
not
in
cached_data
[
'
metadata
'
]:
need_reload
=
False
elif
str
(
request
)
not
in
BmaAccess
.
__saved_requests
\
and
cached_data
[
'
metadata
'
][
'
block
'
]
<
self
.
_network
.
latest_block
:
and
cached_data
[
'
metadata
'
][
'
block
'
]
<
self
.
_network
.
latest_block
:
need_reload
=
True
need_reload
=
True
else
:
else
:
need_reload
=
True
need_reload
=
True
ret_data
=
self
.
_data
[
cache_key
]
[
'
value
'
]
ret_data
=
cached_data
[
'
value
'
]
else
:
else
:
need_reload
=
True
need_reload
=
True
ret_data
=
request
.
null_value
ret_data
=
request
.
null_value
...
@@ -181,6 +161,7 @@ class BmaAccess(QObject):
...
@@ -181,6 +161,7 @@ class BmaAccess(QObject):
:return: The cached data
:return: The cached data
:rtype: dict
:rtype: dict
"""
"""
data
=
self
.
_get_from_cache
(
request
,
req_args
,
get_args
)
data
=
self
.
_get_from_cache
(
request
,
req_args
,
get_args
)
need_reload
=
data
[
0
]
need_reload
=
data
[
0
]
ret_data
=
data
[
1
]
ret_data
=
data
[
1
]
...
@@ -203,6 +184,8 @@ class BmaAccess(QObject):
...
@@ -203,6 +184,8 @@ class BmaAccess(QObject):
@pyqtSlot
(
int
,
dict
,
dict
,
int
)
@pyqtSlot
(
int
,
dict
,
dict
,
int
)
def
handle_reply
(
self
,
request
,
req_args
,
get_args
,
tries
):
def
handle_reply
(
self
,
request
,
req_args
,
get_args
,
tries
):
if
request
==
blockchain
.
UD
:
pass
reply
=
self
.
sender
()
reply
=
self
.
sender
()
logging
.
debug
(
"
Handling QtNetworkReply for {0}
"
.
format
(
str
(
request
)))
logging
.
debug
(
"
Handling QtNetworkReply for {0}
"
.
format
(
str
(
request
)))
cache_key
=
BmaAccess
.
_gen_cache_key
(
request
,
req_args
,
get_args
)
cache_key
=
BmaAccess
.
_gen_cache_key
(
request
,
req_args
,
get_args
)
...
@@ -238,6 +221,7 @@ class BmaAccess(QObject):
...
@@ -238,6 +221,7 @@ class BmaAccess(QObject):
:return: The future data
:return: The future data
:rtype: dict
:rtype: dict
"""
"""
def
handle_future_reply
(
reply
):
def
handle_future_reply
(
reply
):
if
reply
.
error
()
==
QNetworkReply
.
NoError
:
if
reply
.
error
()
==
QNetworkReply
.
NoError
:
strdata
=
bytes
(
reply
.
readAll
()).
decode
(
'
utf-8
'
)
strdata
=
bytes
(
reply
.
readAll
()).
decode
(
'
utf-8
'
)
...
...
This diff is collapsed.
Click to expand it.
src/cutecoin/core/registry/identity.py
+
2
−
1
View file @
0b2cabdd
...
@@ -193,6 +193,7 @@ class Identity(QObject):
...
@@ -193,6 +193,7 @@ class Identity(QObject):
:return: The list of the certifiers of this community in BMA json format
:return: The list of the certifiers of this community in BMA json format
"""
"""
certifiers
=
community
.
bma_access
.
get
(
self
,
qtbma
.
wot
.
CertifiersOf
,
{
'
search
'
:
self
.
pubkey
})
certifiers
=
community
.
bma_access
.
get
(
self
,
qtbma
.
wot
.
CertifiersOf
,
{
'
search
'
:
self
.
pubkey
})
if
certifiers
==
qtbma
.
wot
.
CertifiersOf
.
null_value
:
if
certifiers
==
qtbma
.
wot
.
CertifiersOf
.
null_value
:
logging
.
debug
(
'
bma.wot.CertifiersOf request error
'
)
logging
.
debug
(
'
bma.wot.CertifiersOf request error
'
)
data
=
community
.
bma_access
.
get
(
self
,
qtbma
.
wot
.
Lookup
,
{
'
search
'
:
self
.
pubkey
})
data
=
community
.
bma_access
.
get
(
self
,
qtbma
.
wot
.
Lookup
,
{
'
search
'
:
self
.
pubkey
})
...
@@ -218,8 +219,8 @@ class Identity(QObject):
...
@@ -218,8 +219,8 @@ class Identity(QObject):
certifier
[
'
cert_time
'
][
'
medianTime
'
]
=
community
.
get_block
(
certifier
[
'
cert_time
'
][
'
medianTime
'
]
=
community
.
get_block
(
certifier_data
[
'
meta
'
][
'
block_number
'
])[
'
medianTime
'
]
certifier_data
[
'
meta
'
][
'
block_number
'
])[
'
medianTime
'
]
certifiers
.
append
(
certifier
)
certifiers
.
append
(
certifier
)
return
certifiers
return
certifiers
return
certifiers
[
'
certifications
'
]
return
certifiers
[
'
certifications
'
]
def
unique_valid_certifiers_of
(
self
,
community
):
def
unique_valid_certifiers_of
(
self
,
community
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment