Giter Site home page Giter Site logo

Comments (5)

MilSci avatar MilSci commented on July 29, 2024

also I just realized to avoid always use async/await when calling the function, you can split up the function to establish async await after it knows it can't get it from the cache... I can write the code for this in about an hour

from template.

MilSci avatar MilSci commented on July 29, 2024

Refactored:

It now is either going to get it straight from the cache, or if it can't, then rely on async/await to keep efficiency up.

export const findGuild = (guildId: string) => {
  const guild = cache.guilds.get(guildId)
  if(guild) return guild; //Return the guild if its in the cache
  
  const getStructuredGuild = async () => {
    const guildStructure = await getGuild(guildId, true) //Get the guild structure
    const shardID = (BigInt(guildStructure.id) >> 22n) % BigInt(botGatewayData.shards)
    const struct = await structures.createGuild(guildStructure as CreateGuildPayload, Number(shardID)); //If not create the structure and set it in the cache
    cache.guilds.set(struct.id, struct);
    return struct; //return it
  };
  return getStructuredGuild();
};

from template.

itohatweb avatar itohatweb commented on July 29, 2024

For me this is more a utility function which you don't need unless you do advanced caching/sweeping.

from template.

itohatweb avatar itohatweb commented on July 29, 2024

I'm not sure when you would need this. In this template all guilds are cached always. There is no such advanced sweeping in there which could cause it to be uncached.

from template.

Skillz4Killz avatar Skillz4Killz commented on July 29, 2024

@itohatweb I would consider implementing gamers dispatchRequirements here and then perhaps this could be useful

from template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.