private User[] GetUsers(StandardDB db, Dictionary <string, object> cache, string[] uids) { if (uids[0] == "#ALL_USER") { return(db.users.ToArray()); } var uidcache = cache["uid-user"] as Dictionary <uint, int>; if (uids[0] == "#BAN_UID") { var banuid = cache["banuid"] as HashSet <uint>; return(banuid.Select(uid => uidcache.TryGetValue(uid, out var idx) ? idx : -1).Where(x => x >= 0) .Select(idx => db.users[idx]).ToArray()); } return(uids.Select(uid => UIDPool.Get(uid)).Where(uid => uid != uint.MaxValue) .Select(uid => uidcache.TryGetValue(uid, out var idx) ? idx : -1).Where(x => x >= 0) .Select(idx => db.users[idx]).ToArray()); }
public IActionResult SomeAnalyse() { if (!TryGetDB(out var db)) { return(StatusCode(404)); } if (!TryGetCache(out var cache)) { return(StatusCode(404)); } string target; HashSet <uint> uids; using (var reader = new JsonTextReader(new StreamReader(HttpContext.Request.Body))) { try { var args = Serializer.Deserialize <string[]>(reader); target = args[0]; var ids = JsonConvert.DeserializeObject <HashSet <string> >(args[1]); uids = ids.Select(uid => UIDPool.Get(uid)).Where(uid => uid != uint.MaxValue).ToHashSet(); if (ids.Contains("#BAN_UID")) { var banuid = cache["banuid"] as HashSet <uint>; uids.UnionWith(banuid); } } catch (Exception e) { LOG.LogError(e.Message); return(StatusCode(500)); } } var ret = SomeAssoc(db, cache, target, uids); GC.Collect(2, GCCollectionMode.Optimized, false, true); return(Content(ret, "text/plain; charset=utf-8")); }
private string[][] GetZanLinks(StandardDB db, Dictionary <string, object> cache, string[] uids, string target) { Console.WriteLine($"here get {uids.Length} uids"); if (target == "to") { var zanfcache = cache["from-zan"] as ILookup <uint, int>; var zanartfcache = cache["from-zanart"] as ILookup <uint, int>; var ansathcache = cache["ans-author"] as Dictionary <uint, uint>; var artathcache = cache["art-author"] as Dictionary <uint, uint>; var zanans = uids.SelectMany(uid => { var id = UIDPool.Get(uid); if (id == uint.MaxValue) { return(Enumerable.Empty <string[]>()); } return(zanfcache[id].Select(idx => { ansathcache.TryGetValue(db.zans[idx].to, out var ath); return new string[] { uid, UIDPool.GetString(ath) }; })); }).Where(pair => pair[1] != null); var zanart = uids.SelectMany(uid => { var id = UIDPool.Get(uid); if (id == uint.MaxValue) { return(Enumerable.Empty <string[]>()); } return(zanartfcache[id].Select(idx => { artathcache.TryGetValue(db.zanarts[idx].to, out var ath); return new string[] { uid, UIDPool.GetString(ath) }; })); }).Where(pair => pair[1] != null); return(zanans.Concat(zanart).ToArray()); } else if (target == "from") { var athanscache = cache["author-ans"] as ILookup <uint, uint>; var athartcache = cache["author-art"] as ILookup <uint, uint>; var zantcache = cache["to-zan"] as ILookup <uint, int>; var zanarttcache = cache["to-zanart"] as ILookup <uint, int>; var zanans = uids.SelectMany(uid => { var id = UIDPool.Get(uid); if (id == uint.MaxValue) { return(Enumerable.Empty <string[]>()); } return(athanscache[id].SelectMany(ansid => zantcache[ansid]) .Select(idx => new string[] { db.zans[idx].from, uid })); }); var zanart = uids.SelectMany(uid => { var id = UIDPool.Get(uid); if (id == uint.MaxValue) { return(Enumerable.Empty <string[]>()); } return(athanscache[id].SelectMany(artid => zanarttcache[artid]) .Select(idx => new string[] { db.zanarts[idx].from, uid })); }); return(zanans.Concat(zanart).ToArray()); } else { return(null); } }