fix: видимость записи при отказе Redis, пароль из пробелов
- версия истории чата хранится в PostgreSQL (chats.version, миграция 0003) и растёт в одной транзакции с сообщением; ключ кэша включает её, поэтому ошибка любой команды Redis не может вернуть устаревшую историю - членство и версия читаются одним запросом; INCR/GET версии в Redis удалены - пароль из одних пробельных символов -> 400 (unit-тест validatePassword) - student-tests/regressions.py: сценарий проверки с Redis ACL -incr и пароль - CI: тот же тест против кода до исправления; все серии трека 1 заново
This commit is contained in:
@@ -84,7 +84,7 @@ func (s *MessageService) Send(ctx context.Context, senderID, chatID, text, idemp
|
||||
return stored, nil
|
||||
}
|
||||
|
||||
// Инвалидация: увеличение версии чата (+ SCAN-удаление в режиме scan).
|
||||
// Версия чата уже увеличена в транзакции записи; здесь только режим scan.
|
||||
if s.cache != nil {
|
||||
s.cache.OnWrite(ctx, chatID)
|
||||
}
|
||||
@@ -102,7 +102,9 @@ func (s *MessageService) List(ctx context.Context, callerID, chatID, cursor stri
|
||||
return nil, "", ErrInvalidInput
|
||||
}
|
||||
|
||||
ok, err := s.chats.IsMember(ctx, chatID, callerID)
|
||||
// Членство и версия истории — одним запросом к PostgreSQL. Версия читается
|
||||
// до истории, поэтому под ключом версии v лежат данные не старее v.
|
||||
version, ok, err := s.chats.MemberVersion(ctx, chatID, callerID)
|
||||
if err != nil {
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
return nil, "", ErrNotFound
|
||||
@@ -113,15 +115,9 @@ func (s *MessageService) List(ctx context.Context, callerID, chatID, cursor stri
|
||||
return nil, "", ErrNotFound
|
||||
}
|
||||
|
||||
// Проверяем кэш. Если версия изменилась между GetVersion и Get — не используем.
|
||||
var versionBefore int64
|
||||
if s.cache != nil {
|
||||
versionBefore = s.cache.GetVersion(ctx, chatID) // ← GetVersion не возвращает ошибку, ок
|
||||
if items, next, hit := s.cache.Get(ctx, chatID, versionBefore, cursor, limit); hit { // ← Get: при ошибке false
|
||||
// Проверяем, что версия не изменилась с момента Set
|
||||
if s.cache.GetVersion(ctx, chatID) == versionBefore {
|
||||
return items, next, nil
|
||||
}
|
||||
if items, next, hit := s.cache.Get(ctx, chatID, version, cursor, limit); hit {
|
||||
return items, next, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,12 +146,8 @@ func (s *MessageService) List(ctx context.Context, callerID, chatID, cursor stri
|
||||
next = encodeCursor(chatID, last.CreatedAt, last.ID)
|
||||
}
|
||||
|
||||
// Записываем в кэш только если версия не изменилась за время чтения БД.
|
||||
if s.cache != nil {
|
||||
versionAfter := s.cache.GetVersion(ctx, chatID)
|
||||
if versionBefore == versionAfter {
|
||||
s.cache.Set(ctx, chatID, versionBefore, cursor, limit, items, next)
|
||||
}
|
||||
s.cache.Set(ctx, chatID, version, cursor, limit, items, next)
|
||||
}
|
||||
return items, next, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user