Skip to content

Commit

Permalink
Merge pull request #88 from mgxd/fix/usage
Browse files Browse the repository at this point in the history
FIX: Usage parsing
  • Loading branch information
mgxd authored Oct 22, 2024
2 parents 8d62649 + 8a87953 commit 224a3f2
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 224a3f2

Please sign in to comment.