Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
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
Show more breadcrumbs
hive
hivemind
Commits
1dfc10fa
Commit
1dfc10fa
authored
6 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
rename context to ctx; prep for stateless
parent
bad1a97d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/api-examples.md
+2
-2
2 additions, 2 deletions
docs/api-examples.md
hive/server/hive_api.py
+14
-9
14 additions, 9 deletions
hive/server/hive_api.py
hive/server/serve.py
+3
-0
3 additions, 0 deletions
hive/server/serve.py
with
19 additions
and
11 deletions
docs/api-examples.md
+
2
−
2
View file @
1dfc10fa
...
@@ -40,8 +40,8 @@ http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_following pa
...
@@ -40,8 +40,8 @@ http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_following pa
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_follow_count params:='{"account":"test-safari"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_follow_count params:='{"account":"test-safari"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_user_feed params:='{"account":"test-safari","skip":0,"limit":20,"c
ontex
t":"test-safari"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_user_feed params:='{"account":"test-safari","skip":0,"limit":20,"ct
x
":"test-safari"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_blog_feed params:='{"account":"test-safari","skip":0,"limit":20,"c
ontex
t":"test-safari"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_blog_feed params:='{"account":"test-safari","skip":0,"limit":20,"ct
x
":"test-safari"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_related_posts params:='{"account":"test-safari","permlink":"tps-report-4-calm-before-the-storm"}'
http -j post http://localhost:8080 jsonrpc=2.0 id=1 method=hive.get_related_posts params:='{"account":"test-safari","permlink":"tps-report-4-calm-before-the-storm"}'
...
...
This diff is collapsed.
Click to expand it.
hive/server/hive_api.py
+
14
−
9
View file @
1dfc10fa
...
@@ -5,7 +5,6 @@ import logging
...
@@ -5,7 +5,6 @@ import logging
from
decimal
import
Decimal
from
decimal
import
Decimal
from
aiocache
import
cached
from
aiocache
import
cached
from
hive.db.adapter
import
Db
from
hive.db.adapter
import
Db
from
hive.db.db_state
import
DbState
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -13,7 +12,13 @@ DB = Db.instance()
...
@@ -13,7 +12,13 @@ DB = Db.instance()
async
def
db_head_state
():
async
def
db_head_state
():
"""
Status/health check.
"""
"""
Status/health check.
"""
return
DbState
.
status
()
sql
=
(
"
SELECT num, created_at, extract(epoch from created_at) ts
"
"
FROM hive_blocks ORDER BY num DESC LIMIT 1
"
)
row
=
DB
.
query_row
(
sql
)
return
dict
(
db_head_block
=
row
[
'
num
'
],
db_head_time
=
str
(
row
[
'
created_at
'
]),
db_head_age
=
int
(
time
.
time
()
-
row
[
'
ts
'
]))
# stats methods
# stats methods
# -------------
# -------------
...
@@ -48,13 +53,13 @@ async def payouts_last_24h():
...
@@ -48,13 +53,13 @@ async def payouts_last_24h():
# discussion apis
# discussion apis
# ---------------
# ---------------
async
def
get_blog_feed
(
account
:
str
,
skip
:
int
,
limit
:
int
,
c
ontex
t
:
str
=
None
):
async
def
get_blog_feed
(
account
:
str
,
skip
:
int
,
limit
:
int
,
ct
x
:
str
=
None
):
"""
Get a blog feed (posts and reblogs from the specified account)
"""
"""
Get a blog feed (posts and reblogs from the specified account)
"""
account_id
=
_get_account_id
(
account
)
account_id
=
_get_account_id
(
account
)
sql
=
(
"
SELECT post_id FROM hive_feed_cache WHERE account_id = :account_id
"
sql
=
(
"
SELECT post_id FROM hive_feed_cache WHERE account_id = :account_id
"
"
ORDER BY created_at DESC LIMIT :limit OFFSET :skip
"
)
"
ORDER BY created_at DESC LIMIT :limit OFFSET :skip
"
)
post_ids
=
DB
.
query_col
(
sql
,
account_id
=
account_id
,
skip
=
skip
,
limit
=
limit
)
post_ids
=
DB
.
query_col
(
sql
,
account_id
=
account_id
,
skip
=
skip
,
limit
=
limit
)
return
_get_posts
(
post_ids
,
c
ontex
t
)
return
_get_posts
(
post_ids
,
ct
x
)
async
def
get_related_posts
(
account
:
str
,
permlink
:
str
):
async
def
get_related_posts
(
account
:
str
,
permlink
:
str
):
...
@@ -82,7 +87,7 @@ def _get_account_id(name):
...
@@ -82,7 +87,7 @@ def _get_account_id(name):
return
DB
.
query_one
(
"
SELECT id FROM hive_accounts WHERE name = :n
"
,
n
=
name
)
return
DB
.
query_one
(
"
SELECT id FROM hive_accounts WHERE name = :n
"
,
n
=
name
)
# given an array of post ids, returns full metadata in the same order
# given an array of post ids, returns full metadata in the same order
def
_get_posts
(
ids
,
c
ontex
t
=
None
):
def
_get_posts
(
ids
,
ct
x
=
None
):
sql
=
"""
sql
=
"""
SELECT post_id, author, permlink, title, preview, img_url, payout,
SELECT post_id, author, permlink, title, preview, img_url, payout,
promoted, created_at, payout_at, is_nsfw, rshares, votes, json
promoted, created_at, payout_at, is_nsfw, rshares, votes, json
...
@@ -90,21 +95,21 @@ def _get_posts(ids, context=None):
...
@@ -90,21 +95,21 @@ def _get_posts(ids, context=None):
"""
"""
reblogged_ids
=
[]
reblogged_ids
=
[]
if
c
ontex
t
:
if
ct
x
:
reblogged_ids
=
DB
.
query_col
(
"
SELECT post_id FROM hive_reblogs
"
reblogged_ids
=
DB
.
query_col
(
"
SELECT post_id FROM hive_reblogs
"
"
WHERE account = :a AND post_id IN :ids
"
,
"
WHERE account = :a AND post_id IN :ids
"
,
a
=
c
ontex
t
,
ids
=
tuple
(
ids
))
a
=
ct
x
,
ids
=
tuple
(
ids
))
# key by id so we can return sorted by input order
# key by id so we can return sorted by input order
posts_by_id
=
{}
posts_by_id
=
{}
for
row
in
DB
.
query_all
(
sql
,
ids
=
tuple
(
ids
)):
for
row
in
DB
.
query_all
(
sql
,
ids
=
tuple
(
ids
)):
obj
=
dict
(
row
)
obj
=
dict
(
row
)
if
c
ontex
t
:
if
ct
x
:
voters
=
[
csa
.
split
(
"
,
"
)[
0
]
for
csa
in
obj
[
'
votes
'
].
split
(
"
\n
"
)]
voters
=
[
csa
.
split
(
"
,
"
)[
0
]
for
csa
in
obj
[
'
votes
'
].
split
(
"
\n
"
)]
obj
[
'
user_state
'
]
=
{
obj
[
'
user_state
'
]
=
{
'
reblogged
'
:
row
[
'
post_id
'
]
in
reblogged_ids
,
'
reblogged
'
:
row
[
'
post_id
'
]
in
reblogged_ids
,
'
voted
'
:
c
ontex
t
in
voters
'
voted
'
:
ct
x
in
voters
}
}
# TODO: Object of type 'Decimal' is not JSON serializable
# TODO: Object of type 'Decimal' is not JSON serializable
...
...
This diff is collapsed.
Click to expand it.
hive/server/serve.py
+
3
−
0
View file @
1dfc10fa
...
@@ -11,6 +11,9 @@ from aiohttp import web
...
@@ -11,6 +11,9 @@ from aiohttp import web
from
jsonrpcserver
import
config
from
jsonrpcserver
import
config
from
jsonrpcserver.async_methods
import
AsyncMethods
from
jsonrpcserver.async_methods
import
AsyncMethods
#from hive.db.adapter import Db
#context = dict(db=Db.instance())
from
hive.conf
import
Conf
from
hive.conf
import
Conf
from
hive.server.condenser_api
import
methods
as
condenser_api
from
hive.server.condenser_api
import
methods
as
condenser_api
...
...
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