Skip to content

Commit

Permalink
FIX: Usage parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Oct 22, 2024
1 parent 8d62649 commit 8a87953
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions migas/server/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,15 @@ async def query_usage_by_datetimes(
unique: bool = False,
) -> int:
async with gen_session() as session:
# break up into 2 SELECT calls
subq = (
select(project.c['timestamp', 'user_id'])
.where(project.c.timestamp.between(start, end))
.subquery()
query = select(func.count()).where(
project.c.timestamp >= start, project.c.timestamp <= end
)
if unique:
stmt = select(func.count(distinct(subq.c.user_id)))
else:
stmt = select(func.count(subq.c.user_id))
res = await session.execute(stmt)
return res.scalars().one()
query = select(func.count(distinct(project.c.user_id))).where(
project.c.timestamp.between(start, end)
)
res = await session.execute(query)
return res.scalar_one_or_none() or 0


async def query_usage(project: Table) -> int:
Expand Down

0 comments on commit 8a87953

Please sign in to comment.