-
Notifications
You must be signed in to change notification settings - Fork 7
Tasks #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Tasks #74
Conversation
app/webhooks/tasks.py
Outdated
| location = fields.String(required=True) | ||
| link = fields.String(required=True) | ||
| description = fields.String() | ||
| archive = fields.Boolean() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем ты добавил в модель новое поле?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для сохранения целостности сущности, так как это поле есть в модели Task. Убрать? На добавление записи это влиять не должно.
|
Создал репозиторий и сервис для работы с моделью Task. В сервис добавил два метода работы с БД. (взять все tasks, взять только активные tasks(archive=False)) Дальше хочу заменить некоторые операции с id для большего удобства чтения кода. |
core/services/task_service.py
Outdated
| tasks = Task.query.options(load_only('archive')).all() | ||
| return tasks | ||
|
|
||
| def get_active_tasks(self): | ||
| tasks = Task.query.filter_by(archive=False).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Работает с базой данных именно репозиторий, и эти все методы переноси в него. А от сервиса вообще избавляемся
app/webhooks/tasks.py
Outdated
| tasks_db = task_db.get_archive_tasks() | ||
| task_active_db = task_db.get_active_tasks() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Но вообще, эти две функции возвращают одинаковый результат...
И давай через сессию пробовать получать значения.
И посмотри старый комент, я там описал как получить только те записи которые необходимы, а не всё из базы, у нас там уже несколько тысяч записей, а ээто довольно накладно, особенно, когда записей станет в 10 раз больше, а для этого нужно ещё один год. Доставай только то, что нужно.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А не, не одно и то же, но всё равно, попробуй сделать запрос про который я писал раньше и всё станет проще.
|
Запросы к бд перенес в репозиторий, сервис удалил. Немного изменил код в tasks.py. Работал только с активными задачами в бд, как ты и писал в комментарии notions. Пока не придумал как сделать лучше hash функцию. Удалил метод разархивации(не нашел ему применения, единственное логи пришлось оставить. Хотелось бы это улучшить). |
kr0t
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть конфликт, в tasks.py добавлена валидация модели для тасков.
| return self.session.get(Task, task_id) | ||
|
|
||
| def get(self, task_id: int) -> Task: | ||
| task = self.get_or_none(task_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Метод может вернуть None, но ты его никак не отлавливаешь.
core/repositories/task_repository.py
Outdated
| return task_list | ||
|
|
||
| def update(self, task: Task) -> Task: | ||
| self.session.add(Task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут должен быть экземпляр класса task, а не Task.
| logger.info(f"Tasks: Archived task ids: {task_ids}") | ||
| return task_ids | ||
|
|
||
| def __unarchive_tasks(self, unarchive_records, task_to_send, tasks_dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core/repositories/user_repository.py
Outdated
|
|
||
| def update(self, user: User) -> None: | ||
| pass | ||
| def update(self, task: User) -> User: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Должен быть user вместо task
core/repositories/user_repository.py
Outdated
| def update(self, task: User) -> User: | ||
| self.session.add(User) | ||
| self.session.commit() | ||
| self.session.refresh(task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И тут
|
Вернул метод __unarchive_tasks(переписал немного его логику). Поправил репозитории. |
00f0065 to
a28e439
Compare
|
Разрешил конфликт в tasks. |

Создал репозиторий для Task. Добавил метод update в репозиторий User.
По поводу репозиториев, нашел такое решение:
https://gist.github.com/uris77/4711015/
Метод create и метод update в репозиториях предлагаю объединить в метод persist. Для этого надо переопределить эти методы в AbstractRepository.
Добавил недостающее поле archive в TaskSchema (app/webhooks/tasks).