Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
feat: The migration script reads from slaves mongo instance (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevforget authored Jan 30, 2023
1 parent 1afe7c2 commit 1771347
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions migration/infrastructure/mongo_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@

from migration.domain.connection import Connection
from tapiriik.database import db

from pymongo import ReadPreference

def get_all_connections() -> List[Connection]:
return [Connection.to_connection(conn) for conn in db.connections.find()]
return [Connection.to_connection(conn) for conn in db.connections.with_options(read_preference=ReadPreference.SECONDARY).find()]


def get_connections_by_partner_name(partner_name: str) -> List[Connection]:
return [Connection.to_connection(conn) for conn in db.connections.find({"Service": partner_name})]
return [Connection.to_connection(conn) for conn in db.connections.with_options(read_preference=ReadPreference.SECONDARY).find({"Service": partner_name})]


def get_connection_by_id(connection_id: ObjectId) -> Connection | None:
connection_dict = db.connections.find_one({"_id": connection_id})
connection_dict = db.connections.with_options(read_preference=ReadPreference.SECONDARY).find_one({"_id": connection_id})
if connection_dict is not None:
return Connection.to_connection(connection_dict)
else:
return None


def get_all_users() -> list:
return list(db.users.find())
return list(db.users.with_options(read_preference=ReadPreference.SECONDARY).find())


def get_user_by_connection_id(connection_id: ObjectId) -> List[dict]:
return list(db.users.aggregate(
return list(db.users.with_options(read_preference=ReadPreference.SECONDARY).aggregate(
[
{
'$match': {
Expand All @@ -45,7 +45,7 @@ def get_user_by_connection_id(connection_id: ObjectId) -> List[dict]:


def get_user_connected_to_decathlon() -> List[dict]:
return list(db.users.aggregate(
return list(db.users.with_options(read_preference=ReadPreference.SECONDARY).aggregate(
[
{
'$match': {
Expand Down

0 comments on commit 1771347

Please sign in to comment.