Skip to content

Commit

Permalink
19.11.2023
Browse files Browse the repository at this point in the history
  • Loading branch information
immisterio committed Nov 19, 2023
1 parent 751957e commit 0fd4732
Show file tree
Hide file tree
Showing 19 changed files with 283 additions and 185 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN wget https://github.com/immisterio/Lampac/releases/latest/download/publish.z
unzip -o publish.zip

RUN rm -f publish.zip && rm -rf ffprobe
RUN touch isdocker

EXPOSE 9118

Expand Down
14 changes: 12 additions & 2 deletions JacRed/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async public Task<ActionResult> Indexers(string apikey, string query, string tit

torrents = res.torrents;

if (res.setcache && !red.evercache)
if (res.setcache && !red.evercache.enable)
memoryCache.Set(memoryKey, torrents, DateTime.Now.AddMinutes(10));
}
}
Expand Down Expand Up @@ -286,7 +286,17 @@ static IEnumerable<TorrentDetails> mergeTorrents(IEnumerable<TorrentDetails> red
if (string.IsNullOrEmpty(i.url) || !i.url.StartsWith("http"))
continue;

torrents.TryAdd(Regex.Replace(i.url, "^https?://[^/]+/", ""), i);
void add(string url) { torrents.TryAdd(Regex.Replace(url, "^https?://[^/]+/", ""), i); }

if (i.urls != null && i.urls.Count > 0)
{
foreach (string u in i.urls)
add(u);
}
else
{
add(i.url);
}
}

return torrents.Values;
Expand Down
8 changes: 4 additions & 4 deletions JacRed/Engine/FileDB/FileDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public partial class FileDB : IDisposable
{
string fdbkey;

public ConcurrentDictionary<string, TorrentDetails> Database = new ConcurrentDictionary<string, TorrentDetails>();

FileDB(string key, bool empty = false)
{
fdbkey = key;
string fdbpath = pathDb(key);

if (!empty && File.Exists(fdbpath))
Database = JsonStream.Read<ConcurrentDictionary<string, TorrentDetails>>(fdbpath) ?? new ConcurrentDictionary<string, TorrentDetails>();
}

public ConcurrentDictionary<string, TorrentDetails> Database = new ConcurrentDictionary<string, TorrentDetails>();


public void Dispose()
Expand All @@ -31,7 +31,7 @@ public void Dispose()
if (openWriteTask.TryGetValue(fdbkey, out WriteTaskModel val))
{
val.openconnection -= 1;
if (val.openconnection <= 0 && !ModInit.conf.Red.evercache)
if (val.openconnection <= 0 && !ModInit.conf.Red.evercache.enable)
openWriteTask.TryRemove(fdbkey, out _);
}
}
Expand Down
49 changes: 34 additions & 15 deletions JacRed/Engine/FileDB/staticDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Jackett;
using JacRed.Engine.CORE;
using JacRed.Models;
Expand Down Expand Up @@ -52,32 +53,26 @@ static string pathDb(string key)
}
#endregion

#region OpenRead / OpenWrite
public static IReadOnlyDictionary<string, TorrentDetails> OpenRead(string key)
#region Open
public static FileDB Open(string key, bool empty = false)
{
if (openWriteTask.TryGetValue(key, out WriteTaskModel val))
return val.db.Database;

if (ModInit.conf.Red.evercache)
if (empty)
{
var fdb = new FileDB(key);
openWriteTask.TryAdd(key, new WriteTaskModel() { db = fdb, openconnection = 1 });
return fdb.Database;
var fdb = new FileDB(key, empty: empty);
var md = new WriteTaskModel() { db = fdb, openconnection = 1 };
openWriteTask.AddOrUpdate(key, md, (k, v) => md);
return fdb;
}

return new FileDB(key).Database;
}

public static FileDB OpenWrite(string key)
{
if (openWriteTask.TryGetValue(key, out WriteTaskModel val))
{
val.openconnection += 1;
val.lastread = DateTime.UtcNow;
return val.db;
}
else
{
var fdb = new FileDB(key, empty: true);
var fdb = new FileDB(key);
openWriteTask.TryAdd(key, new WriteTaskModel() { db = fdb, openconnection = 1 });
return fdb;
}
Expand All @@ -100,5 +95,29 @@ public static void SaveChangesToFile()
catch { }
}
#endregion


#region Cron
async public static Task Cron()
{
while (true)
{
await Task.Delay(TimeSpan.FromMinutes(10));

if (!ModInit.conf.Red.evercache.enable || 0 >= ModInit.conf.Red.evercache.validHour)
continue;

try
{
foreach (var i in openWriteTask)
{
if (DateTime.UtcNow > i.Value.lastread.AddHours(ModInit.conf.Red.evercache.validHour))
openWriteTask.TryRemove(i.Key, out _);
}
}
catch { }
}
}
#endregion
}
}
Loading

0 comments on commit 0fd4732

Please sign in to comment.