Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Support fetching READ inbox items with a time bound
天舟f060a4beb414
diff --git a/api/inbox.go b/api/inbox.goindex 0d3f429dcc..6ca282739d 100644--- a/api/inbox.go+++ b/api/inbox.go@@ -64,6 +64,8 @@ type InboxFind struct {// Domain specific fieldsReceiverId *int+ // If specified, then it will only fetch "UNREAD" item or "READ" item whose activity created after "CreatedAfterTs"+ ReadCreatedAfterTs *int64}func (find *InboxFind) String() string {diff --git a/frontend/src/store/modules/inbox.ts b/frontend/src/store/modules/inbox.tsindex aa7a5b4688..8011de4af9 100644--- a/frontend/src/store/modules/inbox.ts+++ b/frontend/src/store/modules/inbox.ts@@ -35,12 +35,6 @@ function convert(};}-function convertSummary(inboxSummary: ResourceObject): InboxSummary {- return {- ...(inboxSummary.attributes as InboxSummary),- };-}-const state: () => InboxState = () => ({inboxListByUser: new Map(),inboxSummaryByUser: new Map(),@@ -68,9 +62,16 @@ const getters = {const actions = {async fetchInboxListByUser({ commit, rootGetters }: any,- userId: PrincipalId+ {+ userId,+ readCreatedAfterTs,+ }: { userId: PrincipalId; readCreatedAfterTs?: number }) {- const data = (await axios.get(`/api/inbox?user=${userId}`)).data;+ var url = `/api/inbox?user=${userId}`;+ if (readCreatedAfterTs) {+ url += `&created=${readCreatedAfterTs}`;+ }+ const data = (await axios.get(url)).data;const inboxList = data.data.map((inbox: ResourceObject) => {return convert(inbox, data.included, rootGetters);});diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vueindex 5d912ca579..c8d098476c 100644--- a/frontend/src/views/Inbox.vue+++ b/frontend/src/views/Inbox.vue@@ -64,6 +64,11 @@class="opacity-70":inboxList="effectiveInboxList(state.readList)"/>+ <div class="mt-2 flex justify-end">+ <button type="button" class="normal-link" @click.prevent="viewOlder">+ View older+ </button>+ </div></div></div></div>@@ -77,6 +82,10 @@ import { Inbox, UNKNOWN_ID } from "../types";import { isDBAOrOwner } from "../utils";import { useRouter } from "vue-router";+// We alway fetch all "UNREAD" items. But for "READ" items, by default, we only fetch the most recent 7 days.+// And each time clicking "View older" will extend 7 days further.+const READ_INBOX_DURATION_STEP = 3600 * 24 * 7;+const ISSUE_TAB = 0;const MEMBER_TAB = 1;@@ -94,6 +103,7 @@ interface LocalState {selectedIndex: number;readList: Inbox[];unreadList: Inbox[];+ readCreatedAfterTs: number;}export default {@@ -107,6 +117,9 @@ export default {selectedIndex: 0,readList: [],unreadList: [],+ readCreatedAfterTs:+ parseInt(router.currentRoute.value.query.created as string) ||+ Math.ceil(Date.now() / 1000) - READ_INBOX_DURATION_STEP,});const currentUser = computed(() => store.getters["auth/currentUser"]());@@ -129,6 +142,7 @@ export default {router.replace({name: "workspace.inbox",hash: "#" + tabItemList[index].hash,+ query: router.currentRoute.value.query,});};@@ -140,7 +154,10 @@ export default {// It will also be called when user logoutif (currentUser.value.id != UNKNOWN_ID) {store- .dispatch("inbox/fetchInboxListByUser", currentUser.value.id)+ .dispatch("inbox/fetchInboxListByUser", {+ userId: currentUser.value.id,+ readCreatedAfterTs: state.readCreatedAfterTs,+ }).then((list: Inbox[]) => {state.readList = [];state.unreadList = [];@@ -200,6 +217,21 @@ export default {state.unreadList = [];};+ const viewOlder = () => {+ state.readCreatedAfterTs -= READ_INBOX_DURATION_STEP;+ router+ .replace({+ name: "workspace.inbox",+ query: {+ ...router.currentRoute.value.query,+ created: state.readCreatedAfterTs,+ },+ })+ .then(() => {+ prepareInboxList();+ });+ };+return {tabItemList,selectTab,@@ -207,6 +239,7 @@ export default {isCurrentUserDBAOrOwner,effectiveInboxList,markAllAsRead,+ viewOlder,};},};diff --git a/server/inbox.go b/server/inbox.goindex 19bbb8ee8b..be6d9a2183 100644--- a/server/inbox.go+++ b/server/inbox.go@@ -23,6 +23,14 @@ func (s *Server) registerInboxRoutes(g *echo.Group) {}inboxFind.ReceiverId = &userId}+ createdAfterStr := c.QueryParams().Get("created")+ if createdAfterStr != "" {+ createdTs, err := strconv.ParseInt(createdAfterStr, 10, 64)+ if err != nil {+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Query parameter created is not a number: %s", createdAfterStr)).SetInternal(err)+ }+ inboxFind.ReadCreatedAfterTs = &createdTs+ }list, err := s.InboxService.FindInboxList(context.Background(), inboxFind)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch inbox list").SetInternal(err)diff --git a/store/inbox.go b/store/inbox.goindex 6203d9be57..2b716b1ad4 100644--- a/store/inbox.go+++ b/store/inbox.go@@ -214,6 +214,9 @@ func findInboxList(ctx context.Context, tx *Tx, find *api.InboxFind) (_ []*api.Iif v := find.ReceiverId; v != nil {where, args = append(where, "receiver_id = ?"), append(args, *v)}+ if v := find.ReadCreatedAfterTs; v != nil {+ where, args = append(where, "(status != 'READ' OR created_ts >= ?)"), append(args, *v)+ }rows, err := tx.QueryContext(ctx, `SELECT