Skip to content

Commit 6639340

Browse files
committed
fix cache
1 parent 31820ae commit 6639340

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

Controllers/SyncController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ActionResult FdbKey(string key)
3636
i.Value.updateTime,
3737
i.Value.fileTime,
3838
path = $"Data/fdb/{HashTo.md5(i.Key).Substring(0, 2)}/{HashTo.md5(i.Key).Substring(2)}",
39-
value = FileDB.OpenRead(i.Key)
39+
value = FileDB.OpenRead(i.Key, cache: false)
4040
}));
4141
}
4242

@@ -60,7 +60,7 @@ public ActionResult FdbTorrents(long time, long start = -1, bool spidr = false)
6060
{
6161
var torrent = new Dictionary<string, TorrentDetails>();
6262

63-
foreach (var t in FileDB.OpenRead(item.Key))
63+
foreach (var t in FileDB.OpenRead(item.Key, cache: false))
6464
{
6565
if (spidr || (start != -1 && start > t.Value.updateTime.ToFileTimeUtc()))
6666
{
@@ -136,7 +136,7 @@ public JsonResult Torrents(long time)
136136

137137
foreach (var item in masterDb.Where(i => i.Value.fileTime > time))
138138
{
139-
foreach (var torrent in FileDB.OpenRead(item.Key))
139+
foreach (var torrent in FileDB.OpenRead(item.Key, cache: false))
140140
{
141141
var _t = (TorrentDetails)torrent.Value.Clone();
142142

Engine/FileDB/FileDB.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,10 @@ public void Dispose()
182182
if (openWriteTask.TryGetValue(fdbkey, out WriteTaskModel val))
183183
{
184184
val.openconnection -= 1;
185-
if (val.openconnection <= 0)
185+
if (0 >= val.openconnection)
186186
{
187-
if (!AppInit.conf.evercache.enable)
187+
if (!AppInit.conf.evercache.enable || (AppInit.conf.evercache.enable && AppInit.conf.evercache.validHour > 0))
188188
openWriteTask.TryRemove(fdbkey, out _);
189-
else if (AppInit.conf.evercache.enable && AppInit.conf.evercache.validHour > 0)
190-
{
191-
if (DateTime.UtcNow > val.lastread.AddHours(AppInit.conf.evercache.validHour))
192-
openWriteTask.TryRemove(fdbkey, out _);
193-
}
194189
}
195190
}
196191
}

Engine/FileDB/staticDB.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void AddOrUpdateMasterDb(TorrentDetails torrent)
111111
#endregion
112112

113113
#region OpenRead / OpenWrite
114-
public static IReadOnlyDictionary<string, TorrentDetails> OpenRead(string key, bool update_lastread = false)
114+
public static IReadOnlyDictionary<string, TorrentDetails> OpenRead(string key, bool update_lastread = false, bool cache = true)
115115
{
116116
if (openWriteTask.TryGetValue(key, out WriteTaskModel val))
117117
{
@@ -126,7 +126,7 @@ public static IReadOnlyDictionary<string, TorrentDetails> OpenRead(string key, b
126126

127127
var fdb = new FileDB(key);
128128

129-
if (AppInit.conf.evercache.enable)
129+
if (cache && AppInit.conf.evercache.enable)
130130
{
131131
var wtm = new WriteTaskModel() { db = fdb, openconnection = 1 };
132132
if (update_lastread)
@@ -141,7 +141,7 @@ public static IReadOnlyDictionary<string, TorrentDetails> OpenRead(string key, b
141141
return fdb.Database;
142142
}
143143

144-
public static FileDB OpenWrite(string key, bool cache = true)
144+
public static FileDB OpenWrite(string key)
145145
{
146146
if (openWriteTask.TryGetValue(key, out WriteTaskModel val))
147147
{
@@ -151,22 +151,19 @@ public static FileDB OpenWrite(string key, bool cache = true)
151151
else
152152
{
153153
var fdb = new FileDB(key);
154-
155-
if (cache)
156-
openWriteTask.TryAdd(key, new WriteTaskModel() { db = fdb, openconnection = 1 });
157-
154+
openWriteTask.TryAdd(key, new WriteTaskModel() { db = fdb, openconnection = 1 });
158155
return fdb;
159156
}
160157
}
161158
#endregion
162159

163160
#region AddOrUpdate
164-
public static void AddOrUpdate(IReadOnlyCollection<TorrentBaseDetails> torrents, bool cache = true)
161+
public static void AddOrUpdate(IReadOnlyCollection<TorrentBaseDetails> torrents)
165162
{
166-
_ = AddOrUpdate(torrents, null, cache);
163+
_ = AddOrUpdate(torrents, null);
167164
}
168165

169-
async public static ValueTask AddOrUpdate<T>(IReadOnlyCollection<T> torrents, Func<T, IReadOnlyDictionary<string, TorrentDetails>, Task<bool>> predicate, bool cache = true) where T : TorrentBaseDetails
166+
async public static ValueTask AddOrUpdate<T>(IReadOnlyCollection<T> torrents, Func<T, IReadOnlyDictionary<string, TorrentDetails>, Task<bool>> predicate) where T : TorrentBaseDetails
170167
{
171168
var temp = new Dictionary<string, List<T>>();
172169

@@ -181,7 +178,7 @@ async public static ValueTask AddOrUpdate<T>(IReadOnlyCollection<T> torrents, Fu
181178

182179
foreach (var t in temp)
183180
{
184-
using (var fdb = OpenWrite(t.Key, cache))
181+
using (var fdb = OpenWrite(t.Key))
185182
{
186183
foreach (var torrent in t.Value)
187184
{

Engine/StatsCron.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async public static Task Run()
3030

3131
foreach (var item in FileDB.masterDb.ToArray())
3232
{
33-
foreach (var t in FileDB.OpenRead(item.Key).Values)
33+
foreach (var t in FileDB.OpenRead(item.Key, cache: false).Values)
3434
{
3535
if (string.IsNullOrEmpty(t.trackerName))
3636
continue;

Engine/Tracks/TracksCron.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async public static Task Run(int typetask)
3434

3535
foreach (var item in FileDB.masterDb.ToArray())
3636
{
37-
foreach (var t in FileDB.OpenRead(item.Key).Values)
37+
foreach (var t in FileDB.OpenRead(item.Key, cache: false).Values)
3838
{
3939
if (string.IsNullOrEmpty(t.magnet))
4040
continue;

0 commit comments

Comments
 (0)