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
1d71d3d2
Commit
1d71d3d2
authored
7 years ago
by
Tim
Browse files
Options
Downloads
Patches
Plain Diff
testing alternate follower iteration
parent
0df4fa3d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/db/methods.py
+19
-10
19 additions, 10 deletions
hive/db/methods.py
hive/server/serve.py
+23
-0
23 additions, 0 deletions
hive/server/serve.py
with
42 additions
and
10 deletions
hive/db/methods.py
+
19
−
10
View file @
1d71d3d2
...
...
@@ -26,18 +26,16 @@ def db_last_block():
# api specific
# ------------
def
get_followers
(
account
:
str
,
skip
:
int
,
limit
:
int
):
q
=
select
([
hive_follows
]).
\
where
(
hive_follows
.
c
.
following
==
account
).
\
skip
(
skip
).
limit
(
limit
)
return
conn
.
execute
(
q
)
def
get_followers
(
account
:
str
,
start
=
None
):
res
=
query
(
"
SELECT follower, created_at FROM hive_follows WHERE following = :account AND
"
"
created_at < IFNULL(:start, NOW()) ORDER BY created_at DESC LIMIT 10
"
,
account
=
account
,
start
=
start
)
return
[[
r
[
0
],
r
[
1
]]
for
r
in
res
.
fetchall
()]
def
get_following
(
account
:
str
,
skip
:
int
,
limit
:
int
):
q
=
select
([
hive_follows
]).
\
where
(
hive_follows
.
c
.
follower
==
account
).
\
skip
(
skip
).
limit
(
limit
)
return
conn
.
execute
(
q
)
def
get_following
(
account
:
str
,
start
:
None
):
res
=
query
(
"
SELECT following, created_at FROM hive_follows WHERE follower = :account AND
"
"
created_at < IFNULL(:start, NOW()) ORDER BY created_at DESC LIMIT 10
"
,
account
=
account
,
start
=
start
)
return
[[
r
[
0
],
r
[
1
]]
for
r
in
res
.
fetchall
()]
def
following_count
(
account
:
str
):
...
...
@@ -52,3 +50,14 @@ def follower_count(account: str):
where
(
hive_follows
.
c
.
following
==
account
).
\
as_scalar
()
return
conn
.
execute
(
q
)
# following/follower counts
# SELECT SUM(IF(follower = 'roadscape', 1, 0)) following, SUM(IF(following = 'roadscape', 1, 0)) followers FROM hivepy.hive_follows WHERE is_muted = 0;
# notifications -- who reblogged you
# SELECT * FROM hive.hive_reblogs r
# JOIN hive_posts p ON r.post_id = p.id
# WHERE p.author = 'roadscape'
# ORDER BY r.created_at DESC;
This diff is collapsed.
Click to expand it.
hive/server/serve.py
+
23
−
0
View file @
1d71d3d2
...
...
@@ -16,6 +16,16 @@ from hive.sbds.sbds_json import ToStringJSONEncoder
from
sqlalchemy
import
create_engine
from
steem.steemd
import
Steemd
from
hive.db.methods
import
(
get_followers
,
get_following
,
following_count
,
follower_count
,
)
logger
=
logging
.
getLogger
(
__name__
)
app
=
bottle
.
Bottle
()
...
...
@@ -50,6 +60,19 @@ def health():
diff
=
diff
,
timestamp
=
datetime
.
utcnow
().
isoformat
())
@app.get
(
'
/followers/<user>
'
)
def
callback
(
user
):
return
dict
(
user
=
user
,
followers
=
get_followers
(
user
))
@app.get
(
'
/followers/<user>/<since>
'
)
def
callback
(
user
,
since
):
return
dict
(
user
=
user
,
followers
=
get_followers
(
user
,
since
))
@app.get
(
'
/head_state
'
)
def
callback
():
return
head_state
()
# JSON-RPC route
# --------------
...
...
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