[SteemSQL Wrapper] Added the info about the delay to API

in #utopian-io7 years ago (edited)

Right now SteemSQL has some issues with performances because of the blockchain size and speed (today Steemit has the biggest number of transactions per day). UPDATE: sorry, it is incorrect, see the arcange's comment.

The result is that SteemSQL sometimes has lagged — for example, right now (when I am writing this post) the delay is 228 minutes. And the lack of information about the delay is a problem for some users.

So I updated SteemSQL Wrapper — now you can get the info about the delay from API.

Example:

curl https://sql.steemhelpers.com/delay
{"delay_seconds": 12018}

The homepage also updated and you can check the delay right on it.

image.png

How this works

  • Firstly, I get the creation date of the last block from SteemSQL
SELECT TOP 1 timestamp FROM Blocks ORDER BY block_num DESC
  • Secondly, I get the creation date of the last block from the blockchain.
blockchain = steem.blockchain.Blockchain()
steemd = steem.steemd.Steemd()
current_block_num = blockchain.get_current_block_num()
current_block = steemd.get_block_header(current_block_num)
blockchain_last_date = datetime.strptime(current_block['timestamp'], "%Y-%m-%dT%H:%M:%S")
  • Thirdly, I compare these two dates.
delay = blockchain_last_date - steemsql_last_date

Commit #1
Commit #2

image



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.


I could remember your previous contributions, so I knew you were working on this project. But to make the work easier for other mods, please add a screenshot next time which shows you logged in to GitHub as proof of work, because you have a different username here on Utopian.


You can contact us on Discord.
[utopian-moderator]

Hey @vladimir-simovic, thanks!
I actually added this proof, see the last image :)

Right now SteemSQL has some issues with performances because of the blockchain size and speed

Lag was not because of blockchain size or speed, but performance of the steemd node use to retrieve blocks.

Firstly, I get the creation date of the last block from SteemSQL

SELECT TOP 1 timestamp FROM Blocks WHERE timestamp >= CONVERT(date, GETUTCDATE()) ORDER BY timestamp DESC

You don't need to use WHERE clause.
The fastest way to retrieve the last block timestamp is:

SELECT TOP 1 timestamp FROM Blocks ORDER BY block_num DESC

Oh, thanks, updated the post and fixed the SQL.

I didn't know there was a possibility of such a long delay. That's useful to know for my analyses.

Congratulations @emptyname! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Hey @emptyname I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 62571.47
ETH 2429.90
USDT 1.00
SBD 2.66