So, the art-counter site broke slightly a few days ago. Nothing serious though.
I had just made a new drawing for the first time in quite a while (96 days) and when I added it to the counter I noticed that it hadn’t underlined the times and made them copy-able like it was supposed to.
For context you can see the difference between the latest top line and the previous bottom one in this screenshot:
This was a slight annoyance, because it’s supposed to make it easier for me to copy the times when I want to insert them into a description when I upload the image somewhere.
The way the system worked then is that when something happened (midnight passed, adding a debt, or a new art entry was added) the system generates the line and just adds it to the log file, then the page just grabs the line and displays it, but using regex it tries to find certain parts, like the times, and make them clickable. But this time, the pattern failed.
So, do I try to figure out why the pattern didn’t match this particular entry and fix it? No. I decide the way I did this was stupid, storing the text as displayed and trying to parse it after the fact. So I get to work re-doing the data storage.
It took a few days, but now instead of storing the log as plain text, it is stored as a JSON encoded array, where each entry is an object representing either a debt or an art. The entry object is represented by a PHP Class where most of the code for interacting with scores and values reside. Storing class instances in JSON required some creativity, because they’re not automatically converted back into class instances when the data is decoded. Instead I had to use a field to determine what type they are (There is one class for art entries and another for debt entries) and then replace the array representing the object that the JSON parser outputs with an actual instance of the class.
In the end the result of a few days of work is a much more robust system where I have a lot more control over how the data is displayed, and it will be a lot easier to change how it is displayed if I want, since the pieces are assembled when the page is rendered, and not when adding to the log like before.
I also ended up removing about a hundred lines of code from the main file which is always a plus.