Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: return the project activity in created_ts DESC order (#1387)

tianzhou84ef8c55beb2
diff --git a/api/activity.go b/api/activity.go
index ddc07e7617..4b735ccae2 100644
--- a/api/activity.go
+++ b/api/activity.go
@@ -296,6 +296,10 @@ type ActivityFind struct {
Level *ActivityLevel
ContainerID *int
Limit *int
+ // If specified, sorts the returned list by created_ts in <<ORDER>>
+ // Different use cases want different orders.
+ // e.g. Issue activity list wants ASC, while view recent activity list wants DESC.
+ Order *SortOrder
}
func (find *ActivityFind) String() string {
diff --git a/api/api.go b/api/api.go
index 4f16292dc5..b0f47e80dd 100644
--- a/api/api.go
+++ b/api/api.go
@@ -22,3 +22,23 @@ func (e RowStatus) String() string {
}
return ""
}
+
+// SortOrder is the sort order for the returned list.
+type SortOrder string
+
+const (
+ // ASC is the sort order to return in ascending order.
+ ASC SortOrder = "ASC"
+ // DESC is the sort order to return in descending order.
+ DESC SortOrder = "DESC"
+)
+
+func (e SortOrder) String() string {
+ switch e {
+ case ASC:
+ return "ASC"
+ case DESC:
+ return "DESC"
+ }
+ return ""
+}
diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.ts
index 52f5be0caa..202bc0f880 100644
--- a/frontend/src/store/modules/activity.ts
+++ b/frontend/src/store/modules/activity.ts
@@ -73,7 +73,7 @@ export const useActivityStore = defineStore("activity", {
this.activityListByIssue.set(issueId, activityList);
},
async fetchActivityListForUser(userId: PrincipalId) {
- const data = (await axios.get(`/api/activity`)).data;
+ const data = (await axios.get(`/api/activity?order=DESC`)).data;
const activityList: Activity[] = data.data.map(
(activity: ResourceObject) => {
return convert(activity, data.included);
@@ -84,7 +84,11 @@ export const useActivityStore = defineStore("activity", {
return activityList;
},
async fetchActivityListForIssue(issueId: IssueId) {
- const queryList = ["typePrefix=bb.issue.", `container=${issueId}`];
+ const queryList = [
+ "typePrefix=bb.issue.",
+ `container=${issueId}`,
+ `order=ASC`,
+ ];
const data = (await axios.get(`/api/activity?${queryList.join("&")}`))
.data;
const activityList: Activity[] = data.data.map(
@@ -104,7 +108,11 @@ export const useActivityStore = defineStore("activity", {
projectId: ProjectId;
limit?: number;
}) {
- const queryList = ["typePrefix=bb.project.", `container=${projectId}`];
+ const queryList = [
+ "typePrefix=bb.project.",
+ `container=${projectId}`,
+ `order=DESC`,
+ ];
if (limit) {
queryList.push(`limit=${limit}`);
}
@@ -123,6 +131,7 @@ export const useActivityStore = defineStore("activity", {
const queryList = [
"typePrefix=bb.sql-editor.query",
`user=${currentUser.id}`,
+ `order=DESC`,
`limit=${limit}`,
// only fetch the successful query history
`level=INFO`,
diff --git a/server/activity.go b/server/activity.go
index 9b47e00031..879e22d6cc 100644
--- a/server/activity.go
+++ b/server/activity.go
@@ -88,6 +88,10 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {
}
activityFind.Limit = &limit
}
+ if orderStr := c.QueryParams().Get("order"); orderStr != "" {
+ order := api.SortOrder(orderStr)
+ activityFind.Order = &order
+ }
activityList, err := s.store.FindActivity(ctx, activityFind)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch activity list").SetInternal(err)
diff --git a/server/webhook.go b/server/webhook.go
index c5107097dd..3a402c8182 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -236,7 +236,6 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
s.l.Warn(msg,
zap.String("project", repo.Project.Name),
)
- return c.String(http.StatusOK, msg)
}
return c.String(http.StatusOK, strings.Join(createdMessageList, "\n"))
})
diff --git a/store/activity.go b/store/activity.go
index 2666269ae5..51822e7d72 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -319,8 +319,11 @@ func findActivityImpl(ctx context.Context, tx *sql.Tx, find *api.ActivityFind) (
payload
FROM activity
WHERE ` + strings.Join(where, " AND ")
+ if v := find.Order; v != nil {
+ query += fmt.Sprintf(" ORDER BY created_ts %s", *v)
+ }
if v := find.Limit; v != nil {
- query += fmt.Sprintf(" ORDER BY updated_ts DESC LIMIT %d", *v)
+ query += fmt.Sprintf(" LIMIT %d", *v)
}
rows, err := tx.QueryContext(ctx, query,