Skip to content

Conversation

@shilin-anton
Copy link
Owner

Add uniqueness validation for DB and some refactoring

@shilin-anton shilin-anton requested a review from Bazys May 20, 2024 16:15
@shilin-anton shilin-anton requested a review from avhitrov May 25, 2024 06:49
Copy link
Collaborator

@avhitrov avhitrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Необходимо изменить источник контекста для БД-функций.
  2. Следует унифицировать интерфейса стораджей
  3. Предлагаю скомпилировать с ключом -race и побомбить сервер на предмет гонок, взяв скрипт отсюда: https://github.com/avhitrov/shorterbomber

return &DataBase{DB: db}, err
}

func (db *DataBase) AddRecord(short, url string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (db *DataBase) AddRecord(short, url string) error {
func (db *DataBase) AddRecord(ctx context.Context, short, url string) error {

Контекст здесь и везде в функциях, обрабатывающих пользовательские запросы, необходимо брать из контекста http-запроса (r.Context()), а не из воздyха. Соответственно, это должно отразиться и в интерфейсе.


var currentStorageType int

func (s Storage) Add(short, url string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Гораздо правильнее будет реализовать единый интерфейс для разных стораджей (in-memory, file, db) и в момент инициализации определять по конфигурации, какой сторадж будет использоваться, инициализировать этот сторадж и скармливать его приемнику интерфейс в сервис или хендлер.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants