GithubHelp home page GithubHelp logo

Comments (5)

mjesun avatar mjesun commented on April 24, 2024

That makes sense to me as well, but let's double check with @jeanlauliac :)

from metro.

jeanlauliac avatar jeanlauliac commented on April 24, 2024

No, the current code is correct afaik. We want to collect only after the delay between the last collection and now (Date.now() - lastCollected) is longer than the period/delay, not shorter. If we collect when it's shorter, then it collects all the time.

I may be wrong somewhere. Did you step-by-step debug and notice that it was collecting all the time?

from metro.

tsyeyuanfeng avatar tsyeyuanfeng commented on April 24, 2024
  /**
   * When restarting packager we want to avoid running the collection over
   * again, so we store the last collection time in a file and we check that
   * first.
   */
  _collectCacheIfOldSync() {
    const {_rootPath} = this;
    const cacheCollectionFilePath = path.join(_rootPath, 'last_collected');
    const lastCollected = Number.parseInt(
      tryReadFileSync(cacheCollectionFilePath) || '',
      10,
    );
    if (
      Number.isInteger(lastCollected) &&
      Date.now() - lastCollected > GARBAGE_COLLECTION_PERIOD
    ) {
      return;
    }
    const effectiveCacheDirPath = path.join(_rootPath, CACHE_SUB_DIR);
    mkdirp.sync(effectiveCacheDirPath);
    collectCacheSync(effectiveCacheDirPath);
    fs.writeFileSync(cacheCollectionFilePath, Date.now().toString());
  }

Currently this function returns when the delay between the last collection and now (Date.now() - lastCollected) is longer than GARBAGE_COLLECTION_PERIOD. I think this isn't what you mean. This function will call collectCacheSync when the delay between the last collection and now (Date.now() - lastCollected) is shorter than GARBAGE_COLLECTION_PERIOD.
@jeanlauliac

from metro.

jeanlauliac avatar jeanlauliac commented on April 24, 2024

Yup, you're correct, I didn't realise it's an early-return condition. Would you mind sending a PR? ^_^

from metro.

tsyeyuanfeng avatar tsyeyuanfeng commented on April 24, 2024

I've sent it.

from metro.

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.