Posts

Updating the Database

avatar of @edicted
25
@edicted
·
·
0 views
·
6 min read

Forgive me Father: For I have sinned!

So I was using MySQL to search for a post that I had written so I could link back to it... and it didn't pop up. Something about regulations. I know I had written it, but it wasn't there. Then I quickly remembered that it's been a while since I've updated my database, so I opened Workbench to see how long.

JUNE!?!

GAH! June? really? Haven't updated since June. So bad. Such a slacker. Terrible terrible terrible. Oh well! Back to the grind... now where was that script that imports my posts into the database... hmmmm. I checked a couple files where I thought it should be but it wasn't there. Then I checked my temporary testing file. The notation I use for temporary files is just 't', so this file was called t.js... I opened it, and the code was there... wow this is embarrassing. A critical function stored in a temporary file. Hm, k.

The only times I have actually used an SQL database like MySQL (pronounced my-sequel but I say my-S-Q-L anyway like a noob) was first during college. That class was actually pretty useful (others not so much). It was one of those situations where the class split up into groups of 5 or whatever and we had a huge group project due at the end of the year worth a massive part of our grade. As we all know these things can turn out poorly with some people leeching and doing like none of the work, but this time it was fine.

My group got together and we all talked about what kind of product we should make. I can't remember other people's idea's but they weren't bad. However, I made a really hard pitch for a poker database, which was pretty uncharacteristic of me at the time. Usually I would just stay out of it and just go along with whatever, but as an aspiring poker player I really thought it would be a good idea if I could get everyone on board with the poker database idea, and it worked (because I was able to tell them exactly how it worked and they realized it would be the easiest path). If I recall correctly it didn't turn out exactly how I wanted it (because there were weird forced requirements like using a primary key auto-increment ID counter), but it did work and we did get a pretty good grade.

I worked on this a bit more years later, but after "Black Friday Poker" (Google it) the entire online poker industry got a bit gutted. Profitability went down and counterparty risk went up. Not a good combination. I stopped playing poker so much... and this was April 2011 so silly me I should have put everything into Bitcoin (oops!). I had certainly heard about it multiple times by then, and I thought it was interesting but just too complex to get involved with at the time.

What do you mean we can't claim we sold a billion golf balls instead of reporting our gambling establishment?!? This is highway robbery!

Hm yeah, so other than that poker database the only other time I've used SQL has been in the context of crypto and Hive, except this time I'm using JavaScript instead of Java... and I'm using the Hive API and HTML/CSS and Node.JS and whatever else. These cascading technologies can become overwhelming quite quickly for one person to wrap their head around, as you can imagine.

I actually created my own clone of Cards Against Humanity on Steem using Java in 2018. Back in those days, some random dev was puttering around and created wrapper code that allowed Java to make native JavaScript calls on Steem, which in turn allowed me to create the game because I didn't know JavaScript but I did know Java (kinda).

The game worked using comments on Steem as the way to play a card in your 'hand' (custom json wasn't even an option because of the wrapper). It was actually pretty funny... I created a 'bot' that played the game just by playing random cards, and sometimes the random answer was funnier than intentional ones. Go figure.

Long story short that wrapper broke for some reason (and the developer quit), which is really weird to me because our core codebase hasn't really changed at all, and I still have scripts from 2018 that still work once I switched over the JavaScript. Java breaking was pretty demoralizing so I quit for a while, as I recall.

Speaking of devs quitting, I'm still randomly amazed that this network is still alive, let alone doing well and grinding out code. If we look at the history of this community over the last six years, the journey has been absolutely abysmal on the "stable environment" scale. You can see for yourself in GitHub how many really talented devs have come and gone. We lost a big chunk when Larimer left because Ned was being a ridiculous dipshit. We lost a big chunk when Ned inevitably sold us down the river to a vulture capitalist. And we've lost good people here and there all throughout the gutter we've been crawling through. If we end up not getting thrown under the bus again over the next 2 or 3 years, we're going to end up making some massive progress like never before.

Just for anyone who isn't familiar with coding... Java may sound a lot like JavaScript, but they might as well be called two completely different things. In fact, Java is much much closer to C++ than it is to JavaScript. I actually like Java quite a bit, which is funny because most devs HATE it. I believe this hate stems from corporate America and has less to do with how Java actually works.

Java is a lot faster than scripting languages like JavaScript and Python, but it also requires you to be more specific with your containers and notation. Java has some features that make it a bit easier than C++, like the garbage collector (you don't have to allocate or deallocate memory to prevent leaks), but these factors also make it a little slower compared to a fully optimized C++ program. Hive Core is built in C++, so it is theoretically quite fast if properly optimized. I find this a bit odd because we never see any of this code even as developers on the outside. Everything is JavaScript interacting with servers and such.

That's the thing about the Internet

The Internet is slow and computers and servers are fast. Scripting languages like JavaScript are very good at what they do. In many scenarios they don't need to be fast or optimized because all they are doing is sending a ping to a server and waiting for a response. The vast majority of the wait-time has nothing to do with code optimization and everything to do with simply waiting for that server on the other side of the world to give you an answer. Once we factor in the fact that JavaScript is essentially the default code for interacting with HTML and webpages... it actually enrages me that learning it in college was not prioritized over Java, C++, and even assembly language. That's corporate America for you.

What was this about again?

Oh yeah... my critical post-import database code was in a temporary t.js file. Remember?!? Yeah anyway so I go to run this code and it scoops the first 100 most recent posts into my database using Node.JS... and then it just stops. Hm, that's weird it should have grabbed more. It's a recursive loop that should keep importing posts until it finds a copy of one already in there.

So I check the code for the bug and what I wrote was the most hackish nonsense ever. Future me was embarrassed for past me. Past me had just gotten the job done ASAP and never made a real solution for importing posts. And guess what? Rather than fix the code I just did some manual inputs to get all six months worth of posts in there. Attaboy!

Basically this code only works if the database is empty. I seriously considered deleting all the data and just reimporting everything but the thought of doing such a thing was so cringe I just couldn't do it. Ah whatever it's all back up to date again, for now. This time if I remember to run that script before it's 100 posts out of date I won't have to do the manual importing. Or I could just, you know, make it actually automated and work for reals. Nah! Life of a dev. Sort of.

Posted Using LeoFinance Beta