Repository: valkey-io/valkey
File: src/expire.c (C)

Code before:
        data.ttl_sum = 0;
        data.ttl_samples = 0;
        data.max_entries = keys_per_loop * 4;
        data.db = db;

        int db_done = 0; /* The scan of the current DB is done? */
        int update_avg_ttl_times = 0, repeat = 0;

        kvstoreScanFunction scan_cb;

        kvstore *kvs = NULL;
        if (db) {
            switch (jobType) {
            case KEYS:
                kvs = db->expires;
                scan_cb = expireScanCallback;
                time_check_rate = 0xf; /* For regular keys we can check the time condition every 16 loop iterations */
                break;
            case FIELDS:
                kvs = db->keys_with_volatile_items;
                scan_cb = fieldExpireScanCallback;
                /* For field-level keys we check the time condition every loop iteration.
                 * This is required since we might perform much more operation per single key with many fields.
                 * Limiting the number of fields we scan in each field makes the overall process less efficient.
                 * So we just perform more clock checks after each iteration. */
                time_check_rate = 0x0;
                break;
            default:
                serverPanic("Unknown active expiry job type %d.", jobType);
            }
        }

        if (db && kvstoreSize(kvs)) dbs_performed++;

        /* Continue to expire if at the end of the cycle there are still
         * a big percentage of keys to expire, compared to the number of keys
         * we scanned. The percentage, stored in config_cycle_acceptable_stale
         * is not fixed, but depends on the configured "expire effort". */
        do {
            if (db == NULL) {
                break; /* DB not allocated since it was never used */
            }

            unsigned long num;
            iteration++;

            /* If there is nothing to expire try next DB ASAP. */
            if ((num = kvstoreSize(kvs)) == 0) {
                db->expiry[jobType].avg_ttl = 0;
                break;
            }

Review comment (suggestion):
```suggestion
                time_check_mask = 0x0;
```

Code after:
        data.ttl_sum = 0;
        data.ttl_samples = 0;
        data.max_entries = keys_per_loop * 4;
        data.db = db;

        int db_done = 0; /* The scan of the current DB is done? */
        int update_avg_ttl_times = 0, repeat = 0;

        kvstoreScanFunction scan_cb;

        kvstore *kvs = NULL;
        if (db) {
            switch (jobType) {
            case KEYS:
                kvs = db->expires;
                scan_cb = expireScanCallback;
                time_check_mask = 0xf; /* For regular keys we can check the time condition every 16 loop iterations */
                break;
            case FIELDS:
                kvs = db->keys_with_volatile_items;
                scan_cb = fieldExpireScanCallback;
                /* For field-level keys we check the time condition every loop iteration.
                 * This is required since we might perform much more operation per single key with many fields.
                 * Limiting the number of fields we scan in each field makes the overall process less efficient.
                 * So we just perform more clock checks after each iteration. */
                time_check_mask = 0x0;
                break;
            default:
                serverPanic("Unknown active expiry job type %d.", jobType);
            }
        }

        if (db && kvstoreSize(kvs)) dbs_performed++;

        /* Continue to expire if at the end of the cycle there are still
         * a big percentage of keys to expire, compared to the number of keys
         * we scanned. The percentage, stored in config_cycle_acceptable_stale
         * is not fixed, but depends on the configured "expire effort". */
        do {
            if (db == NULL) {
                break; /* DB not allocated since it was never used */
            }

            unsigned long num;
            iteration++;

            /* If there is nothing to expire try next DB ASAP. */
            if ((num = kvstoreSize(kvs)) == 0) {
                db->expiry[jobType].avg_ttl = 0;
                break;
            }