Skip to content

Commit 7860519

Browse files
committed
fix
1 parent 7adbfe7 commit 7860519

File tree

4 files changed

+71
-49
lines changed

4 files changed

+71
-49
lines changed

Controllers/ApiController.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ HashSet<int> getCategoryIds(TorrentDetails t, out string categoryDesc)
462462
{
463463
Dictionary<string, (TorrentDetails torrent, string title, string Name, List<string> AnnounceUrls)> temp = new Dictionary<string, (TorrentDetails, string, string, List<string>)>();
464464

465-
foreach (var torrent in torrents.Values)
465+
foreach (var torrent in torrents.Values.OrderByDescending(i => i.createTime).ThenBy(i => i.trackerName == "selezen"))
466466
{
467467
var magnetLink = MagnetLink.Parse(torrent.magnet);
468468
string hex = magnetLink.InfoHashes.V1OrV2.ToHex();
@@ -551,11 +551,14 @@ void UpdateTitle()
551551
}
552552
#endregion
553553

554-
if (torrent.sid > t.torrent.sid)
555-
t.torrent.sid = torrent.sid;
554+
if (torrent.trackerName != "selezen")
555+
{
556+
if (torrent.sid > t.torrent.sid)
557+
t.torrent.sid = torrent.sid;
556558

557-
if (torrent.pir > t.torrent.pir)
558-
t.torrent.pir = torrent.pir;
559+
if (torrent.pir > t.torrent.pir)
560+
t.torrent.pir = torrent.pir;
561+
}
559562

560563
if (torrent.createTime > t.torrent.createTime)
561564
t.torrent.createTime = torrent.createTime;
@@ -605,7 +608,7 @@ List<ffStream> FFprobe(TorrentDetails t, out HashSet<string> langs)
605608
return t.ffprobe;
606609
}
607610

608-
var streams = TracksDB.Get(t.magnet, t.types);
611+
var streams = TracksDB.Get(t.magnet, t.types, onlydb: true);
609612
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
610613
if (streams == null)
611614
return null;
@@ -650,7 +653,8 @@ List<ffStream> FFprobe(TorrentDetails t, out HashSet<string> langs)
650653
});
651654
}
652655

653-
memoryCache.Set(cachekey, Results, DateTime.Now.AddMinutes(5));
656+
if (AppInit.conf.evercache.enable && AppInit.conf.evercache.validHour == 0)
657+
memoryCache.Set(cachekey, Results, DateTime.Now.AddMinutes(5));
654658

655659
return Json(new RootObject() { Results = Results });
656660
}
@@ -853,7 +857,7 @@ void AddTorrents(TorrentDetails t)
853857
langs = TracksDB.Languages(t, t.ffprobe);
854858
else
855859
{
856-
var streams = TracksDB.Get(t.magnet, t.types);
860+
var streams = TracksDB.Get(t.magnet, t.types, onlydb: true);
857861
langs = TracksDB.Languages(t, streams ?? t.ffprobe);
858862
}
859863

Controllers/SyncController.cs

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using JacRed.Engine;
1+
using JacRed.Engine;
52
using JacRed.Engine.CORE;
63
using JacRed.Models;
74
using JacRed.Models.Details;
85
using JacRed.Models.Sync.v2;
96
using Microsoft.AspNetCore.Mvc;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Threading;
11+
using System.Threading.Tasks;
1012

1113
namespace JacRed.Controllers
1214
{
1315
public class SyncController : BaseController
1416
{
15-
private static readonly object masterDbCacheLock = new object();
16-
private static Dictionary<string, TorrentInfo> masterDbCache;
17-
private static DateTime masterDbCacheUpdated = DateTime.MinValue;
17+
static Dictionary<string, TorrentInfo> masterDbCache;
18+
19+
public static void Configuration()
20+
{
21+
masterDbCache = FileDB.masterDb.OrderBy(i => i.Value.fileTime).ToDictionary(k => k.Key, v => v.Value);
22+
23+
ThreadPool.QueueUserWorkItem(async _ =>
24+
{
25+
while (true)
26+
{
27+
await Task.Delay(TimeSpan.FromMinutes(10));
28+
try { masterDbCache = FileDB.masterDb.OrderBy(i => i.Value.fileTime).ToDictionary(k => k.Key, v => v.Value); } catch { }
29+
}
30+
});
31+
}
32+
1833

1934
[Route("/sync/conf")]
20-
public JsonResult Configuration()
35+
public JsonResult SyncConf()
2136
{
2237
return Json(new
2338
{
@@ -52,19 +67,6 @@ public ActionResult FdbTorrents(long time, long start = -1, bool spidr = false)
5267
bool nextread = false;
5368
int take = 2_000, countread = 0;
5469
var collections = new List<Collection>(take);
55-
56-
// Use static cache updated every 10 minutes
57-
if (masterDbCache == null || (DateTime.Now - masterDbCacheUpdated) > TimeSpan.FromMinutes(10))
58-
{
59-
lock (masterDbCacheLock)
60-
{
61-
if (masterDbCache == null || (DateTime.Now - masterDbCacheUpdated) > TimeSpan.FromMinutes(10))
62-
{
63-
masterDbCache = FileDB.masterDb.OrderBy(i => i.Value.fileTime).ToDictionary(k => k.Key, v => v.Value);
64-
masterDbCacheUpdated = DateTime.Now;
65-
}
66-
}
67-
}
6870

6971
foreach (var item in masterDbCache.Where(i => i.Value.fileTime > time))
7072
{
@@ -85,16 +87,18 @@ public ActionResult FdbTorrents(long time, long start = -1, bool spidr = false)
8587

8688
if (t.Value.ffprobe == null || t.Value.languages == null)
8789
{
88-
var _t = (TorrentDetails)t.Value.Clone();
89-
90-
var streams = TracksDB.Get(_t.magnet, _t.types);
90+
var streams = TracksDB.Get(t.Value.magnet, t.Value.types, onlydb: true);
9191
if (streams != null)
9292
{
93+
var _t = (TorrentDetails)t.Value.Clone();
9394
_t.ffprobe = streams;
9495
_t.languages = TracksDB.Languages(_t, streams);
96+
torrent.TryAdd(t.Key, _t);
97+
}
98+
else
99+
{
100+
torrent.TryAdd(t.Key, t.Value);
95101
}
96-
97-
torrent.TryAdd(t.Key, _t);
98102
}
99103
else
100104
{
@@ -137,19 +141,6 @@ public JsonResult Torrents(long time)
137141

138142
int take = 2_000;
139143
var torrents = new List<Models.Sync.v1.Torrent>(take+1);
140-
141-
// Use static cache updated every 10 minutes
142-
if (masterDbCache == null || (DateTime.Now - masterDbCacheUpdated) > TimeSpan.FromMinutes(10))
143-
{
144-
lock (masterDbCacheLock)
145-
{
146-
if (masterDbCache == null || (DateTime.Now - masterDbCacheUpdated) > TimeSpan.FromMinutes(10))
147-
{
148-
masterDbCache = FileDB.masterDb.OrderBy(i => i.Value.fileTime).ToDictionary(k => k.Key, v => v.Value);
149-
masterDbCacheUpdated = DateTime.Now;
150-
}
151-
}
152-
}
153144

154145
foreach (var item in masterDbCache.Where(i => i.Value.fileTime > time))
155146
{
@@ -158,7 +149,7 @@ public JsonResult Torrents(long time)
158149
var _t = (TorrentDetails)torrent.Value.Clone();
159150
_t.updateTime = item.Value.updateTime;
160151

161-
var streams = TracksDB.Get(_t.magnet, _t.types);
152+
var streams = TracksDB.Get(_t.magnet, _t.types, onlydb: true);
162153
if (streams != null)
163154
{
164155
_t.ffprobe = streams;

Engine/Tracks/TracksDB.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ namespace JacRed.Engine
1717
{
1818
public static class TracksDB
1919
{
20+
public static void Configuration()
21+
{
22+
foreach (var folder1 in Directory.GetDirectories("Data/tracks"))
23+
{
24+
foreach (var folder2 in Directory.GetDirectories(folder1))
25+
{
26+
foreach (var file in Directory.GetFiles(folder2))
27+
{
28+
string infohash = folder1.Substring(12) + folder2.Substring(folder1.Length + 1) + Path.GetFileName(file);
29+
Console.WriteLine(infohash);
30+
31+
try
32+
{
33+
var res = JsonConvert.DeserializeObject<ffprobemodel>(File.ReadAllText(file));
34+
if (res?.streams != null && res.streams.Count > 0)
35+
Database.TryAdd(infohash, res);
36+
}
37+
catch { }
38+
}
39+
}
40+
}
41+
}
42+
2043
static Random random = new Random();
2144

2245
static ConcurrentDictionary<string, ffprobemodel> Database = new ConcurrentDictionary<string, ffprobemodel>();
@@ -42,7 +65,7 @@ public static bool theBad(string[] types)
4265
return false;
4366
}
4467

45-
public static List<ffStream> Get(string magnet, string[] types = null)
68+
public static List<ffStream> Get(string magnet, string[] types = null, bool onlydb = false)
4669
{
4770
if (types != null && theBad(types))
4871
return null;

Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class Program
1515
{
1616
public static void Main(string[] args)
1717
{
18+
TracksDB.Configuration();
19+
SyncController.Configuration();
20+
ApiController.getFastdb(update: true);
21+
1822
ThreadPool.QueueUserWorkItem(async _ =>
1923
{
2024
while (true)

0 commit comments

Comments
 (0)