0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-23 00:40:19 +00:00

Revert "feat: Added pagination support to environments endpoint ()" ()

This reverts commit 4664cd2d88.
This commit is contained in:
Nick Satterly 2023-12-22 11:51:20 +01:00 committed by GitHub
parent e10287142f
commit d50131b9e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 34 deletions
alerta
database
backends/postgres
base.py
models
views

View file

@ -632,14 +632,14 @@ class Backend(Database):
# ENVIRONMENTS
def get_environments(self, query=None, page=None, page_size=None):
def get_environments(self, query=None, topn=1000):
query = query or Query()
select = f"""
SELECT environment, severity, status, count(1) FROM alerts
WHERE {query.where}
GROUP BY environment, CUBE(severity, status)
"""
result = self._fetchall(select, query.vars, limit=page_size)
result = self._fetchall(select, query.vars, limit=topn)
severity_count = defaultdict(list)
status_count = defaultdict(list)
@ -654,7 +654,7 @@ class Backend(Database):
total_count[row.environment] = row.count
select = """SELECT DISTINCT environment FROM alerts"""
environments = self._fetchall(select, {}, limit=page_size, offset=(page - 1) * page_size)
environments = self._fetchall(select, {})
return [
{
'environment': e.environment,
@ -663,14 +663,6 @@ class Backend(Database):
'count': total_count[e.environment]
} for e in environments]
def get_environments_count(self, query=None):
query = query or Query()
select = """
SELECT COUNT(DISTINCT environment) FROM alerts
WHERE {where}
""".format(where=query.where)
return self._fetchone(select, query.vars).count
# SERVICES
def get_services(self, query=None, topn=1000):

View file

@ -204,10 +204,7 @@ class Database(Base):
# ENVIRONMENTS
def get_environments(self, query=None, page=1, page_size=100):
raise NotImplementedError
def get_environments_count(query: Query = None) -> int:
def get_environments(self, query=None, topn=1000):
raise NotImplementedError
# SERVICES

View file

@ -542,12 +542,8 @@ class Alert:
# get environments
@staticmethod
def get_environments(query: Query = None, page: int = 1, page_size: int = 100) -> List[str]:
return db.get_environments(query, page, page_size)
@staticmethod
def get_environments_count(query: Query = None) -> int:
return db.get_environments_count(query)
def get_environments(query: Query = None) -> List[str]:
return db.get_environments(query)
# get services
@staticmethod

View file

@ -480,30 +480,19 @@ def get_topn_standing():
@jsonp
def get_environments():
query = qb.alerts.from_params(request.args, customers=g.customers)
total = Alert.get_environments_count(query)
paging = Page.from_params(request.args, total)
environments = Alert.get_environments(query, page=paging.page, page_size=paging.page_size)
environments = Alert.get_environments(query)
if environments:
return jsonify(
status='ok',
environments=environments,
page=paging.page,
pageSize=paging.page_size,
pages=paging.pages,
more=paging.has_more,
total=total
total=len(environments)
)
else:
return jsonify(
status='ok',
message='not found',
environments=[],
page=paging.page,
pageSize=paging.page_size,
pages=paging.pages,
more=paging.has_more,
total=0
)