DBlog.io - Decentralized Blogging Platform - Backend improvement
utopian-io·@mahdiyari·
0.000 HBDDBlog.io - Decentralized Blogging Platform - Backend improvement
<center> <sub>source: pixabay.com</sub></center> GitHub repo: https://github.com/mahdiyari/dblog-backend Commit1: [link](https://github.com/mahdiyari/dblog-backend/commit/47988ac48ceeed123c9983b213c7dbf821448e10) Commit2: [link](https://github.com/mahdiyari/dblog-backend/commit/608b9f876e3d00dd32f083069004a561479a7c7f) Commit3: [link](https://github.com/mahdiyari/dblog-backend/commit/58022e6a290704ff3d2a299954078106d1ed8cba) Commit4: [link](https://github.com/mahdiyari/dblog-backend/commit/5d644cfe8e64d8ce265f1c8522b9bbdc5c8a8775) Small fix: [link](https://github.com/mahdiyari/dblog-backend/commit/87a16378f67fee2f0c2b358e660515b9c942388d) 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](https://github.com/mahdiyari/dblog-backend) and a front-end [here](https://github.com/mahdiyari/dblog) A demo will be available here: https://dev.onsteem.com (back-end and front-end connected) *** #### Development <center> <sub>source: pixabay.com</sub></center> We need to keep all posts and comments from our users in the database to provide faster experience to the visitors! After the first login, a function will be called to start syncing user comments and posts. This function will make POST requests to an RPC node then it will insert all posts and comments to the database. We will keep all the posts in the `posts` table and all comments in the `comments` table in the MySQL database. Of course, we can't insert all post's data into the database because of storage limits, we will keep only constant information which is not changeable! like permlink, author, id, category, created, and etc MySQL structure is also updated: [link to the commit](https://github.com/mahdiyari/dblog-backend/commit/e3ee20dc266c6d3b73b556d3a0db89a4d04b41ac) <center> <sub>source: pixabay.com</sub></center> Later we can sort posts by `timestamp` and `category`and detect similar posts by using `category`! After syncing all posts and comments from any user, we will need to stream blocks for the coming posts and comments. This job is done by `/stream_sync.js` We used a simple array for saving recent posts and comments to prevent from adding duplicate values to the database! Because MySQL `INSERT` is not fast enough. If a user broadcasts multiple edit posts, we may add them multiple times to the database. I explained much about this in the codes: ``` // we will use this function to save recent posts in the 'posts[]' // if a user broadcasts multiple 'edited posts' to the blockchain // we may add same post, multiple times to the database // because INSERT in MySQL is not fast enough to insert data // and that may process multiple INSERTs at the same time // we can check posts against 'posts[]' variable // to ensure there will not be any duplicate posts in the database // this function will return a number from 0 to 500 as index (posts[index]) // to create a pool of posts to keep recent posts and delete older posts let index = 0 let maxIndex = 500 const postsIndex = async () => { if (index < maxIndex) index += 1 else index = 0 return index } ``` Then we can use following code to save post's id in the `posts` array: ``` let index = await postsIndex() posts[index] = comment.id // or post.id ``` Recent posts and comments will be added to the `posts` array from `index` 1 to the 500, then `index` will be changed to 0, and we will replace old posts with newer posts! We can check for duplicate values by using `indexOf()` method which is much faster than checking database. I used an ExpressJS server for receiving new registered users by a post request which is faster than checking the database every second! I will work on the new APIs to display posts in the front-end with some extra features! *** <center> <sub>source: pixabay.com</sub></center> This contribution submitted to the https://utopian.io Support this new project with your contributions, upvotes, and witness votes. Thanks for your great support:) Regards, 2018-07-16
👍 defango, khalilalfamahera, gambit.coin, siyulaters, tariksaran, safwan10000, jamesmovic, ghevangelist, ardian27, makrotheblack, endee, yudiana, mrxplicit, flozockt, cy23, kim24, iamjimmy, esteem77, ekkah, jhiecortez, fajarharapan, laboh, sundararaj, barut, silentpartnerio, mirnasahara, gangplankhg, emirfirlar, foodtaster, ulfiatu.akiya, anam01, paulo380, essteem, steemvests, good-korma, zay-arasi, terry00, justinzidi3, walidchabir, handfree42, peewillz, rodonlegend, ibook-ishare, ita-soa, freemon, belemo, tailslide, virgo27, bit6in, hendraman, apartphilosopher, bdkazi, bhim, achmadyani, miaplexuscaleb, peewills, detromix87, supreme7, annassatu, aniesta, bgmuna, marianadagraca, luckykar, rositasilvia, syahhiran, criticalbarny, steem100, supersteemian, crystalhuman, tanisha786, jpgalih, ilhampratama, greenville, raju1, emongnovaostia, akram7, tysir, advsamadhan, thesiam, dennis041713, bangkarnen, ascendedmonkey, khalilputra, dieantwoord, deletefacebook, multiplicity, magneticstorm, calisthenox, munkiioh, xcrushurskullx, chrisppierre, dayosoyinka, steempals, buymoremoney, crystalrobot, war-tp, not-a-gamer, ismailrafael, gakimov, ernoldlvb, mayib, susyoke, ocn, sirmiraculous, dubbio, marcozina, sshowoff, oniraphaeleu, hamzatuliqbal, dheaulvani, dekna.steem, caristeem, linuxsteem, choobymaverick, chukwuebuka, radhitmeldita, abiq, irawatismk, iqbalteampoison, vinakim, baixiian, jinxizhen, mishamardiah, wardatulaini, hasnawati, hafidhiati92, ira-steem, mangaku, mrs.riyah28, tutorial.steem, steepshoot, phanton, kok.bisa, steemja, ijar85, niena, rayboma, ardaar, betterbiskuit, gozben24, hera-b, tissuesurgeon, samcofy, kelvinikke, korkorjkk15, sugarpie, korkorjkk, stone1010, kwabena1995, fayamba, giddensk7, nanaboateng, steemramos, dacosta, fredrick4u, caxton, toroo, jazzyon, rosemary4u, aaakosuahumble, eddymania, aaaaaa-aaaaaakay, sarahhhh, christinebeauty, jcmansah, precioussteem, aabhi, umut1905, mahdiyari, dabstars, yazannew, dabstar, arzy, laiyuehta, czechman, steemitstats, chey, sukro, akpos, coinchek, gangplankhq, sulwati, spoke, wakeupnd, santinhos, blockchaincat, luciancovaci, peak.endrule, wealth4good, yckifoundation, livelifelong, bosjaya, bullish27, foxesal, vishal007, brumest, benleemusic, fahri, dedeleyman, ermolop, jayboss, armguinan, sitiaishah, patlu, tesselart, leomolina, abbyrich, baancap, baandak, baanggal, tm50, commenthunter, chandra1987, nature.indonesia, razpor, youngogmarqs, altionsan, kumpaiy, topinon, dream77124, hibashah1992, rahulwasan, coindzs, csmedia, nurhasib, vibelita, crescendoofpeace, garudas, bold42, green07, torico, boyasyie, lindalex, salahudeen, freerolll, onelovedtube, hibernated, samaz0r, hadimemories, kenanqhd, valorforfreedom, gaminghd, alfajri78, veganroma, travelcontinuous, rachmaddarmawan, alexabsolute, aperterikk, happymichael, penjahit, scottshots, jeffmcmullen, d00k13, darkfuseion, gisi, illuminationst8, ilazramusic, ulqu3, brettblue, travellit, izzymiyake, nuttapon, romafedorov, mata.lensa, zainenn, inoobgamer, onelove.curation, d3nv3r, oliverstoney, sextant, taskmanager, prizeportal, awilix, blem, zapped, instantvoter, jedimasteryoda, drakos, subha193, dipoabasch, bibakipcikcam, samathist, gooze, logan9852, britcoins, kimchi-king, open-asset, khunfarang, khunpoom, mrandreas, digital-jesus, mrstaf, bryanj4, teachblogger, vitkolesnik, bargolis, world-travel-pro, coquiunlimited, yvonneinoregon, theleapingkoala, reekadoh, artax89, molamola, blockgators, moscato, bco, mzuami, steemobserver, ladybirdec, xanderslee, krissy330, osmania, leguidecrypto, ian19, masjenk, asrizalmustafa, nonsqtr, saidaplc, molang, otrip, marcost4, talentclub, filmmasochist, jraysteem, veenang, leverager, majalahsahabat, felixgarciap, lynbabe10, hoscker, herdi.steemit, gabo.trip, elohim4, srl-zone, divyajoshi, drmaizo, chillingotter, ivan-perez-anies, dresden, alexisvalera, aniestudio, assus, dresden1, dresden2, dresden3, serlanvet, torkot, oscarps, humoalex, siucatti, clacrax, oscarcc89, galberto, juancar347, rnunez09, armonia, decomoescribir, aleli, ficciones, simnrodrguez, trenz, neiraurdaneta, dojeda, marpa, kristal24, rahesi, abnerpantoja, psicomar, valentinagrv, poetarojo, zenkly, bourrbakia, darius86, yimiipsa, elinderzambrano, gusvzla, risckylu, kaizag, dragonflyarrow, miguelfiguera, cesinfenianos, critic-on, mrstrange, silasvogt, moises-moran, gabrielamosqueda, poesiaempirica, joseacabrerav, salvao, iaberius, wilins, adncabrera, nahupuku, johannfrare, chejonte, teevmoore, rjguerra, zeleiracordero, yosuandoni, marlyncabrera, blockgatorsarmy, maslowmission, dlife, phototutorials, altcoinpost, polbot, circlemotogp, neeqi, neopatriarch, toddmck, amymya, amayahaley21, crowbarmama, exzorltg, dnews, mdshide, willsaldeno, gasparcha, adventuroussoul, theaudgirl, presidentialline, gwbush, umber123, shermanedwards, gwashington, jjay, camuel, jist, dsongs, kenmelendez, openmind3000, astramar, dianation, muchukunda, ivan174, mahidulislam, alokkamboj, meehks, loshcat, coolon2709, jbrrd, enjoyinglife, neopch, hattaarshavin, aidarojaswriter, iwanderela, scottychams, vincy, graylan, bitmycoin, apasia.tech, steembet.asia, poppypyro, jduarte, vickaboleyn, yenipaola, zulfikar-fx, thewestlifeboy, pepiflowers, osobiggie, asrizal, ibrasteem, acryptoverse, asadpannu, worlddreams, thepaperboy, orphanstrust, manchow, ramratan, sarthakgupta, razadilberkhan, rs1007, khankamran, searchnew, lallimohan005, aquafi, voronenka, ashikstd, prasadyelwande, investprosper, lksingha, arjun9, mdarob, jeffjagoe, hasi111, abhishek2130, acesontop, ruhi, edrivegom, gug711, shahzadkhatri, syedumair, lexorka, savetheworldd, sshamem, ekramhossain1616, imtiaz09, anasboss, flyingcam, m2i, sarvona, motlhamme, frederichs, elleok, aashusood, steemit-bot, traderr, mememaster-1, raheelkhan, fatkat, duckmast3r, transcript-junky, mixedmentalarts, anixon, cryptowarrior88, nameless-berk, bitcoinsandgravy, saifullahskp, unfixable, jonathanjoestar, ranahussnainali, binagautam33, farin007, cannabiscup, adeshvy, molikhatun, emergehealthier, dulborah, basant111, dontmiss, sundram, rakibmaruf24, mgibson, sundram1221, karann, ramizmurtaza, ravinderji, keuxal, angrysage, cryptoclient, deb180, diliptilwani, skmrahaman, himanshu91, tayaba81, binoy2018, bikalpa, kuberman, sam.smith, maruf107, ramjee121, jjaamaall, easybuck, thethreehugs, sunit, sanks7, ramanraina19, gautambnod, maruf0123, mr-bike, indianteam, basiruddin1, pradipolee, fractal-team, vasilisapor2, gabriel11, huyngo3008, ankitbabaji, manishlahre30, mike191, india1st, karibu, ucanis, sallauddin12, d-pend, sabina10, onetwoone, only4you, sushant769, liberviarum, jamespradhan, stevecronin, ehabakhdar, ayamksh714, thinkingmind, bitshares-sweden, sagheer46, ishan89, grintsch, sarao, misterking, andyjaypowell, wonder.human, jainlove, gank, healthgym, arafatsaikatcse, enigma105, kailash1997, gutenmorgen, jpyadav123, anikas, greatrooko, truefact, cryptojb, tigerstripe, anurag001, bhavikpatel74055, annabel1122, abrahman5, indian.dtuber, abdullahdogar, dmitriysar, siv, chamelykhatun, ahsaaaan, nomadics, dilan91, anishag, thrinadh, judicar, kzaid7, reenarao, rndness222, sanketbhatkar, abhisheks0608, pkbasnet, hunny100dev, pallabmax, holovision, vaansteam, hashclub, ultimatesupport, mosleh, vedantsingh, drubo4145, sisaket, uday20, navrosekalsi, earn-with-dk, important-to-us, sscomm, hanin, cryptoloverboy, asrarahmed, giosou, ashok979, piyushnishandar, johnbeauty, hitesh0898, heer, mwaqar17, maykocan, preet121, moms43, momimalhi, allinone7, warthas, tdre, bhavinkhalasi, deewon56, haris112014, ankit14192, redouanemez, freeicotoken, akpatiyal, asad21221, deepakratna, alan369, priti, yougotresteemed, jadusab, payelmia, nirajkothari, vickyjangid, haider143, touseefk, ik33541, archana25, prabhat13, la2410, towhidkhondoker, khaled1234, salmankpk1986, firesteem, vinodkasaragadda, sandeshsharma, deepbardhan, amarsinghktp, livingtoday, vander, ahmedsharif, indianculture1, achiron, mayankpatel9998, sangeetha4545, theinr2inr, zemex, jaissaurabh, faheem023, twigg, mbhushan133, bibekchandra, cryptokuber, amar15, sheriii786, indiacryptonews, tausifajmal, silentworld, almamun298, viralreward3, shojalnuman, abhishektechguru, steemrewards101, viralasia, shyamoli, vikas23, yourhealthcare, yadavji535, katy24, btctop1, jack333, cryptos999, davitone, gaurav9971, riazuddin101, imowaisab, mintu1319, djaay, graphyhunt, nurulafsar03, cryptossi, don-thomas, faady92, teutonium, arvindkhushi, violetmed, azhar1, hkniazi, rloriaux, salah10, dalwar8, nightwolf, ladytsfrancine, yarleni, pariza, voxmortis, muchlisjones, mysportshop, perezgerald, stocksfetcher, aimlessjasim, chrone, vikas4233, sheikhmarjan1, dglob, moneymantra, luthfinanda, tahsin-420, cgastra, j-traore, billal133, majidawan, dinkar, rohit4588, kochstudio, lindamary, dhanu1998, austino, maujmasti, amir110, spikykevin, lee.daniel, blk007, gaboski, dion66, dattabitcoin, lerikaweb, yassersb, sheikhsalman, harkuch, zafarishafiq, prabh12, amang9578, dheeraj705, hiranraj, runicar, bolomalin808, sujanmaharjan, rawalien, utopian-io, upheaver, nahin007, arunmormare, mcoinz79, amitak, sadiajahan22, anujkumar, parthakp, elena1987, yak15, umair72023, vjjoe, umarsharif49, avinashdebnath, mike11, sharmin.papri, pario, cryptomeme, punjolife, quazonx, kashan39, marverick984, fatimaah, harriet1, alamgir140491, ferdinandlee, future24, nayem233, infoslink, candyshop, janusface, vipins, kaminchan, imawreader, dadabosade, learnguitar, drkuldipmengi, gtpjoker, oadissin, deepak1987658, prajwal619, ajaycrypto18, infinity999, mike949, anwarabdullah, rabby20, itsluv, notsoperfectlife, santasingh, sazzad7137, jsdjack, jigarpatel35, safizone, bimboola42, aaatish, smartpoint, macbaren, rokonujjaman, kiaragabriel, trendygirl, rubi0102, hk1000, mithilsood, farhankhan4321, vikasvyas2384, kirankumarflyer, abhi3700, franz100, anuragforu, universelnews, cryptobols, aliyaarooj, talhashafiq119, bilalrana, huan00087, biomanu, chotho, axellhail, sst, tahoorsaleem, podinatutorials, injamam90, ushnorahman, porwalk82, thirdeye7, farukcom, alyssaluhun, bradfordtennyson, artcreator, youssefb, talhaejaz, azeem1, ykhan60, alokkumar121, sundesha, askmoneyguru, risingstars, himanitokas, vrushabh, pacolimited, aadians143, arjun01, stockcrypto, adminap, steemminder, moneyphoenix, arcanu, venusisme, shamim1992, satyamchauhan, crypt0age, airdropmagic, tutchpa, debasishpurulia, valiantegg, zhivot, jhonmedas, sujitsawant, mnipa, kmmukul, almajan, imsmahanta1, ritikdokania23, faizanalii, deepak0007, marvindean, medicbtom, unitedcrypto, zizuflorin, housnerd, sairot, chetanpatel, drvivekbindra, techtools, farhanali59, shhrhzad77, mshehzad7, vsrsatish, rimsha7, siddharthvishnoi, technicalgupshup, arkkart, stezcoins, gifty-e, nazmul79, balcon07, gohain, abhijeetcg, marwanfitra93, thegreatparas, kmayegaindia, srinivasaniyeng, tamurah, alexbronz, hossain1, mirroroftime, pratap339, himanshusindhal, yousuf24, sureshnsnet, rubeldas, sajjadkabir1, techlife, ikramellahi, mohiuddinmukul, maharima, mauryis, mrogy1, praditya, marcusantoniu26, almohageer, yazanstorm, krevasilis, akbarbadsha, diaehamzawi, sthitaprajna, c-wan, vichar, bansi, ilovesmoke, vishal8086, riesaxon, stmeme, avii1209, babar005, bhaveshsavani, yassine11, rishishrt, handicraft, smartaqaa, rjsharmatop, dannybobo, alok25, trendingsports, mamun1237, navesumar, saubhikbiswas338, ashikbd1, saraheasy, siyaa, askari, berniesanders, nextgencrypto, thecyclist, engagement, iflagtrash, randomthoughts, thedelegator, ngc,