DBlog.io - Decentralized Blogging Platform - Backend improvement

in utopian-io •  6 months ago

source: pixabay.com

GitHub repo: https://github.com/mahdiyari/dblog-backend
Commit: https://github.com/mahdiyari/dblog-backend/commit/7c59954b65ef9d3951da7203b9a480417c96d122
& https://github.com/mahdiyari/dblog-backend/commit/7309faba7e7f29d217d730351daae963b170ee12

Recently I announced a new opensource project: https://steemit.com/onsteem/@mahdiyari/announcement-onsteem-a-better-interface-on-the-steem-blockchain

I started developing back-end for this project called Dblog.io (new name)!
We will have a back-end here and a front-end here

A demo will be available here: https://dev.onsteem.com (back-end and front-end connected)


Note: if you are not a developer, you can skip this part!

After some research, I found a way to manage more MySQL connections without disconnection errors!
I create a pool of MySQL connections instead of a single MySQL connection

const pool = mysql.createPool({
  connectionLimit: 1000,
  host: config.db.host,
  user: config.db.user,
  password: config.db.pw,
  database: config.db.name,
  charset: 'utf8mb4'

This pool will handle up to 1,000 live MySQL connections. Also, the pool is able to add extra connections to the queue!

Then, I coded the MySQL query() method to return a promise

const con = {}
con.query = async (query, val) => {
  if (val) {
    let qu = await new Promise((resolve, reject) => {
      pool.query(query, val, (error, results) => {
        if (error) reject(new Error(error))
    return qu
  } else {
    let qu = await new Promise((resolve, reject) => {
      pool.query(query, (error, results) => {
        if (error) reject(new Error(error))
    return qu

This function will create new MySQL connections in the pool then will return received result of query, after returning result, that connection will be released in the pool to handle another query!
Also, handling errors are easier in this function!

I edited all functions to return a promise, with this, about 100 lines of codes reduced!
Also, syncing user's data is under development, I just uploaded a file and development will be inside that file.

(Actually, I'm going to add some minor features to the Steemauto then switch back to the Dblog)

This contribution submitted to the https://utopian.io
Support this new project by your upvotes and witness votes. Thanks for your great support:)


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

I see that you followed some of my advice :) that's great. Good job on the update.

Let's go for the review:

In any case it's nice to see that's you made some great improvements on your project. Keep up the good work!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.

Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.


Thanks for your great review
using .then() allows me to run multiple codes at the same time! and await/async pauses functions for a little time!
That is how I used them! in the main function (top-level function) I decided to use then() to allow other processes to run at the same time! (for example, syncing blocks which I will add)


Hey @gregory.latinier
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

Contributing on Utopian
Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hey @mahdiyari
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Following you, thanks.

This is terrific. I missed the introduction post from a month ago but went back and read it. Great application that you are making. A serious front end application is needed big time. The fact that you are tying the back end yourself means a lot.

It is great to see. This should only build on the success of steemauto....another great app that benefits the steem blockchain.

It's good news. Best regards @mahdiyari

Congratulations @mahdiyari!
Your post was mentioned in the Steemit Hit Parade in the following category:

  • Upvotes - Ranked 9 with 1098 upvotes