scrub usernames from analysis - WIP
parent
49b2cf6bd0
commit
4e8f30a2bc
|
@ -0,0 +1,15 @@
|
|||
if (typeof user == 'undefined') throw 'Usage: mongo lichess --eval \'user="username"\' script.js';
|
||||
|
||||
user = db.user4.findOne({ _id: user });
|
||||
|
||||
if (!user || user.enabled || !user.erasedAt) throw 'Erase with lichess CLI first.';
|
||||
|
||||
const randomUserId = () => {
|
||||
const idChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const idLength = 8;
|
||||
let result = '';
|
||||
for (let i = idLength; i > 0; --i) result += idChars[Math.floor(Math.random() * idChars.length)];
|
||||
return result;
|
||||
};
|
||||
|
||||
const id = randomUserId();
|
|
@ -26,17 +26,14 @@ final class Analyser(
|
|||
sendAnalysisProgress(analysis, complete = true) >>- {
|
||||
Bus.publish(actorApi.AnalysisReady(game, analysis), "analysisReady")
|
||||
Bus.publish(InsertGame(game), "gameSearchInsert")
|
||||
val cost = analysis.uid.fold(1) { requester =>
|
||||
if (game.userIds has requester) 1 else 2
|
||||
}
|
||||
requesterApi.save(analysis, cost).unit
|
||||
requesterApi.save(analysis, game.userIds).unit
|
||||
}
|
||||
}
|
||||
}
|
||||
case Some(_) =>
|
||||
analysisRepo.save(analysis) >>
|
||||
sendAnalysisProgress(analysis, complete = true) >>-
|
||||
requesterApi.save(analysis, 1).unit
|
||||
requesterApi.save(analysis, Nil).unit
|
||||
}
|
||||
|
||||
def progress(analysis: Analysis): Funit = sendAnalysisProgress(analysis, complete = false)
|
||||
|
|
|
@ -10,17 +10,9 @@ case class Analysis(
|
|||
studyId: Option[String],
|
||||
infos: List[Info],
|
||||
startPly: Int,
|
||||
uid: Option[User.ID], // requester lichess ID
|
||||
by: Option[User.ID], // analyser lichess ID
|
||||
date: DateTime
|
||||
) {
|
||||
|
||||
def requestedBy = uid | "lichess"
|
||||
|
||||
def providedBy = by | "lichess"
|
||||
|
||||
def providedByLichess = by exists (_ startsWith "lichess-")
|
||||
|
||||
lazy val infoAdvices: InfoAdvices = {
|
||||
(Info.start(startPly) :: infos) sliding 2 collect { case List(prev, info) =>
|
||||
info -> {
|
||||
|
@ -64,8 +56,6 @@ object Analysis {
|
|||
studyId = r strO "studyId",
|
||||
infos = Info.decodeList(raw, startPly) err s"Invalid analysis data $raw",
|
||||
startPly = startPly,
|
||||
uid = r strO "uid",
|
||||
by = r strO "by",
|
||||
date = r date "date"
|
||||
)
|
||||
}
|
||||
|
@ -75,8 +65,6 @@ object Analysis {
|
|||
"studyId" -> o.studyId,
|
||||
"data" -> Info.encodeList(o.infos),
|
||||
"ply" -> w.intO(o.startPly),
|
||||
"uid" -> o.uid,
|
||||
"by" -> o.by,
|
||||
"date" -> w.date(o.date)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2,24 +2,34 @@ package lila.analyse
|
|||
|
||||
import org.joda.time._
|
||||
import reactivemongo.api.bson.{ BSONBoolean, BSONInteger }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.memo.CacheApi
|
||||
import lila.user.User
|
||||
|
||||
final class RequesterApi(coll: Coll)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
final class RequesterApi(coll: Coll, cacheApi: CacheApi)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
private val formatter = format.DateTimeFormat.forPattern("yyyy-MM-dd")
|
||||
|
||||
def save(analysis: Analysis, value: Int): Funit =
|
||||
coll.update
|
||||
.one(
|
||||
$id(analysis.uid | "anonymous"),
|
||||
$inc("total" -> 1) ++
|
||||
$inc(formatter.print(DateTime.now) -> value) ++
|
||||
$set("last" -> analysis.id),
|
||||
upsert = true
|
||||
)
|
||||
.void
|
||||
private[analyse] val requesterCache =
|
||||
cacheApi.notLoadingSync[Analysis.ID, lila.user.User.ID](256, "analyse.requester") {
|
||||
_.expireAfterWrite(10 minutes).build()
|
||||
}
|
||||
|
||||
def save(analysis: Analysis, playerIds: List[User.ID]): Funit =
|
||||
requesterCache.getIfPresent(analysis.id) ?? { requester =>
|
||||
val cost = if (playerIds has requester) 1 else 2
|
||||
coll.update
|
||||
.one(
|
||||
$id(requester),
|
||||
$inc("total" -> 1) ++
|
||||
$inc(formatter.print(DateTime.now) -> cost) ++
|
||||
$set("last" -> analysis.id),
|
||||
upsert = true
|
||||
)
|
||||
.void
|
||||
}
|
||||
|
||||
def countTodayAndThisWeek(userId: User.ID): Fu[(Int, Int)] = {
|
||||
val now = DateTime.now
|
||||
|
|
Loading…
Reference in New Issue