Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions alembic/versions/a4b515b8757c_add_indices_for_fast_match_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Add indices for fast match lookup

Revision ID: a4b515b8757c
Revises: 58c1b2a9640f
Create Date: 2024-08-19 14:10:04.813456

"""

# revision identifiers, used by Alembic.
revision = 'a4b515b8757c'
down_revision = '58c1b2a9640f'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade(engine_name):
print("Upgrading {}".format(engine_name))
op.create_index('ix_gs_matches_start_date', 'gs_matches', ['start_date'], postgresql_using='brin')
op.create_index('ix_gs_matches_status', 'gs_matches', ['status'])
op.alter_column('gs_matches', 'details', type_=postgresql.JSONB)
op.alter_column('gs_matches', 'match_statistics', type_=postgresql.JSONB)


def downgrade(engine_name):
print("Downgrading {}".format(engine_name))
op.alter_column('gs_matches', 'match_statistics', type_=postgresql.JSON)
op.alter_column('gs_matches', 'details', type_=postgresql.JSON)
op.drop_index('ix_gs_matches_status')
op.drop_index('ix_gs_matches_start_date')
19 changes: 12 additions & 7 deletions driftbase/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Boolean,
)
from sqlalchemy import DDL, event
from sqlalchemy.dialects.postgresql import ENUM, INET, JSON, UUID
from sqlalchemy.dialects.postgresql import ENUM, INET, JSON, UUID, JSONB
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship, backref
from sqlalchemy.schema import Sequence, Index
Expand Down Expand Up @@ -178,9 +178,9 @@ class Client(ModelBase):
def is_online(self):
_, heartbeat_timeout = get_client_heartbeat_config()
if (
self.status == "active"
and self.heartbeat + datetime.timedelta(seconds=heartbeat_timeout)
>= utcnow()
self.status == "active"
and self.heartbeat + datetime.timedelta(seconds=heartbeat_timeout)
>= utcnow()
):
return True
return False
Expand Down Expand Up @@ -346,16 +346,20 @@ class Match(ModelBase):
server_id = Column(Integer, nullable=False)
start_date = Column(DateTime, nullable=True, server_default=utc_now)
end_date = Column(DateTime, nullable=True)
status = Column(String(50), nullable=True)
status = Column(String(50), nullable=True, index=True)
num_players = Column(Integer, nullable=True)
max_players = Column(Integer, nullable=True)
game_mode = Column(String(50), nullable=True)
map_name = Column(String(50), nullable=True)
match_statistics = Column(JSON, nullable=True)
details = Column(JSON, nullable=True)
match_statistics = Column(JSONB, nullable=True)
details = Column(JSONB, nullable=True)
status_date = Column(DateTime, nullable=True)
unique_key = Column(String(50), nullable=True)

__table_args__ = (
Index('ix_gs_matches_start_date', 'start_date', postgresql_using='brin'),
)


class MatchPlayer(ModelBase):
__tablename__ = "gs_matchplayers"
Expand Down Expand Up @@ -572,6 +576,7 @@ class FriendInvite(ModelBase):

UniqueConstraint(token, name="uq_ck_friend_invites_token")


event.listen(
CorePlayer.__table__,
"after_create",
Expand Down
2 changes: 1 addition & 1 deletion scripts/local-alembic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ set +a

docker run --rm -ti --network backend --env-file $DIR/local.env \
--entrypoint /bin/bash \
app_drift-base:latest \
app-drift-base:latest \
-c "alembic $(printf "${1+ %q}" "$@")"
2 changes: 1 addition & 1 deletion scripts/local-provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docker run --rm -ti --network backend --env-file $DIR/local.env \
--mount "type=bind,source=$CONFIG_STORE,target=$CONFIG_STORE" \
--mount "type=bind,source=$CONFIG_ORIGIN,target=$CONFIG_ORIGIN" \
--entrypoint /bin/bash \
app_drift-base:latest \
app-drift-base:latest \
-c "driftconfig provision-tenant $TENANT $DEPLOYABLE"
driftconfig cache $CONFIG