Perchance Saving Bugs

There were a few instances where in the editor ended up failing to “save”, but the generator saving process still succeeded and is still recorded in the revisions.

I was editing my generator hub page that day and saved it by clicking on the save button and then it errors after a classic 20 seconds…

I decided to check the DevTools network and it shows all the details behind that saving process, and things look suspicious, until the revisions told me wrong.

@perchance

  • perchance@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    4 months ago

    This isn’t a full answer, but one thing which should help a bit here is to use this:

    let generatorNameArray = ["generator-name", "another-generator-name"];
    let generatorDataArray = await fetch("https://perchance.org/api/getGeneratorStats?names="+generatorNameArray.join(",")).then(r => r.json());
    

    instead of making lots of separate requests (currently 138 requests for stats on power-generator-manager according to DevTools). The reason this should help is because (IIRC), the save process waits for the full page to reload in case of (currently undocumented) dynamic $meta info, and I think lots of requests may slow it down a bit.

    I’ve added some code to potentially help speed things up, and ensure that “saving…” immediately shows when you hit ctrl+s, and prevents other save processes from starting at the same time, which I think could cause a traffic jam of save requests, or something.

    Either way, the current code I have for saving isn’t super ideal - it’s definitely slower than it should be, especially for lots of imports, but the above two things should hopefully help a little bit until I get around to speeding it up.

    • BluePower@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      3 months ago

      Thanks for the code snippet, I’m actually working on another Generator Manager update and have started to implement this into the total view calculation function (totalStats()). Though I’m not sure if this could be used for the view counters in the generator items.

      For now, the code for the function looks a bit like this:

      Code for a future Generator Manager update
      async function totalStats() {
        // We already had the URLs from all the generators on the page and compiled them through the all_link variable
        let tot = await fetch("https://perchance.org/api/getGeneratorStats?names="+all_link.joinItems(",")).then(r => r.json());
        let ftot = 0;
        for (let v of tot.data.map(x => x.views)) {
          ftot += v; // Add up to make the total views
        }
        // We need to set two total view counters in the top banner and on the Statistics section in the About page
        for (let el of document.querySelectorAll(".tstxt")) {
          el.innerHTML = enableRawStats ? ftot.toLocaleString() : formatNumber(ftot);
        }
        // Set the total views counter in the top banner
      }; totalStats();
      

      The totalStats() function is now an async function and sets the total view counter on the top banner right away instead of just returning the value of it, so this time I no longer need a timer that does this job consecutively anymore. And this greatly reduced the delay for the total views counter to appear.


      I’ve added some code to potentially help speed things up, and ensure that “saving…” immediately shows when you hit ctrl+s,

      Is this implementation still triggers the “error” whenever the save fails after 20 seconds, and instead of staying on the “saving…” state indefinitely? I see that nowadays it still occasionally ends up on the “error” state.

      @[email protected] pinging once again.

      • perchance@lemmy.worldM
        link
        fedilink
        English
        arrow-up
        1
        ·
        3 months ago

        Does it get suck on ‘error’? Occasional errors (like once every few days maybe) are normal but it shouldn’t get stuck there.

        • BluePower@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          3 months ago

          IIRC sometimes it did end up on the “error” and goes back to the save button. Maybe that is because of bad connection or something, I’ve been receiving a lot of occasional delays (that took up to 30 minutes to just load a generator) but not as common as now. Maybe that’s why it affected the save, because that loading process also interferes the saving function.


          Edit: Yeah, as of right now, when I’m saving my hub page, the “bad connection” thing happened, and the save button remained on “saving” state when the console told me that the 20-second timeout was exceeded. This is strange, because before that the save button would end up on the “error” state.