diff options
author | regnat <rg@regnat.ovh> | 2021-05-10 17:45:53 +0200 |
---|---|---|
committer | regnat <rg@regnat.ovh> | 2021-05-10 17:47:14 +0200 |
commit | d5d19582ef24af3754f7a2675f43d6828c3a8638 (patch) | |
tree | 0a01b9f285dc7b467f44bcc71faad98ef2155b38 /src/libstore/nar-info-disk-cache.cc | |
parent | ab96c1ee504674ddbb0a09796af87d898e2bf753 (diff) |
Simplify the realisations disk cache
Diffstat (limited to 'src/libstore/nar-info-disk-cache.cc')
-rw-r--r-- | src/libstore/nar-info-disk-cache.cc | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 84ce7972f..9dd81ddfb 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -42,9 +42,8 @@ create table if not exists NARs ( create table if not exists Realisations ( cache integer not null, outputId text not null, - content blob, -- Json serialisation of the realisation, or empty if present is true + content blob, -- Json serialisation of the realisation, or null if the realisation is absent timestamp integer not null, - present integer not null, primary key (cache, outputId), foreign key (cache) references BinaryCaches(id) on delete cascade ); @@ -113,22 +112,22 @@ public: state->insertRealisation.create(state->db, R"( - insert or replace into Realisations(cache, outputId, content, timestamp, present) - values (?, ?, ?, ?, 1) + insert or replace into Realisations(cache, outputId, content, timestamp) + values (?, ?, ?, ?) )"); state->insertMissingRealisation.create(state->db, R"( - insert or replace into Realisations(cache, outputId, timestamp, present) - values (?, ?, ?, 0) + insert or replace into Realisations(cache, outputId, timestamp) + values (?, ?, ?) )"); state->queryRealisation.create(state->db, R"( - select present, content from Realisations + select content from Realisations where cache = ? and outputId = ? and - ((present = 0 and timestamp > ?) or - (present = 1 and timestamp > ?)) + ((content is null and timestamp > ?) or + (content is not null and timestamp > ?)) )"); /* Periodically purge expired entries from the database. */ @@ -265,12 +264,12 @@ public: if (!queryRealisation.next()) return {oUnknown, 0}; - if (queryRealisation.getInt(0) == 0) + if (queryRealisation.isNull(0)) return {oInvalid, 0}; auto realisation = std::make_shared<Realisation>(Realisation::fromJSON( - nlohmann::json::parse(queryRealisation.getStr(1)), + nlohmann::json::parse(queryRealisation.getStr(0)), "Local disk cache")); return {oValid, realisation}; |