Skip to content

Commit

Permalink
Cleanup mysql generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianZaremba committed Dec 11, 2024
1 parent f2939ed commit 942dc68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
10 changes: 5 additions & 5 deletions pkg/cbng/database/cluebot/cluebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ func (ci *CluebotInstance) GenerateVandalismId(logger *logrus.Entry, ctx context
_, span := metrics.OtelTracer.Start(ctx, "database.cluebot.GenerateVandalismId")
defer span.End()

var vandalismId int64

db := ci.getDatabaseConnection()
defer db.Close()

res, err := db.Exec("INSERT INTO `vandalism` (`id`,`user`,`article`,`heuristic`,`reason`,`diff`,`old_id`,`new_id`,`reverted`) VALUES (NULL, ?, ?, '', ?, ?, ?, ?, 0)", user, title, reason, diffUrl, previousId, currentId)
if err != nil {
logger.Errorf("Error running query: %v", err)
span.SetStatus(codes.Error, err.Error())
return vandalismId, err
return 0, err
}
if vandalismId, err := res.LastInsertId(); err != nil {

vandalismId, err := res.LastInsertId()
if err != nil {
logger.Errorf("Failed to get insert id: %v", err)
span.SetStatus(codes.Error, err.Error())
return vandalismId, err
return 0, err
}

logger.Debugf("Generated id %v", vandalismId)
Expand Down
20 changes: 5 additions & 15 deletions pkg/cbng/wikipedia/wikipedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,11 @@ func (w *WikipediaApi) GetWarningLevel(l *logrus.Entry, parentCtx context.Contex
matches := regexp.MustCompile(`<!-- Template:uw-[a-z]*(\d)(im)? -->.*(\d{2}:\d{2}, \d+ [a-zA-Z]+ \d{4} \(UTC\))`).FindAllStringSubmatch(page.Data, -1)
level := 0
for _, match := range matches {
mlevel, err := strconv.Atoi(match[1])
if err != nil {
span.SetStatus(codes.Error, err.Error())
logger.Warnf("Failed to parse '%v' into int: %v", match[1], err)
continue
}
if match[2] != "" {
t, err := time.Parse("15:04, 02 January 2006 (MST)", match[2])
if err != nil {
span.SetStatus(codes.Error, err.Error())
logger.Warnf("Failed to parse '%v' into time: %v", match[2], err)
continue
}
if mlevel > level && t.Second() <= (2*24*60*60) {
level = mlevel
if matchLevel, err := strconv.Atoi(match[1]); err == nil {
if t, err := time.Parse("15:04, 02 January 2006 (MST)", match[2]); err == nil {
if matchLevel > level && t.Second() <= (2*24*60*60) {
level = matchLevel
}
}
}
}
Expand Down

0 comments on commit 942dc68

Please sign in to comment.