Skip to content

Commit f9c3438

Browse files
authored
Merge pull request #945 from mapswipe/dev
Release - Fix community statsboard issue
2 parents 308f8b4 + e9c49f6 commit f9c3438

File tree

9 files changed

+133
-96
lines changed

9 files changed

+133
-96
lines changed

community-dashboard/app/Base/configs/apollo.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ const link: ApolloLinkFromClient = ApolloLink.from([
3131

3232
const apolloOptions: ApolloClientOptions<NormalizedCacheObject> = {
3333
link,
34-
cache: new InMemoryCache(),
34+
cache: new InMemoryCache({
35+
typePolicies: {
36+
// NOTE: Singleton types that have no identifying field can use an empty
37+
// array for their keyFields.
38+
FilteredStats: {
39+
keyFields: [],
40+
},
41+
},
42+
}),
3543
assumeImmutableResults: true,
3644
defaultOptions: {
3745
query: {

community-dashboard/app/views/Dashboard/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import {
1919
const COMMUNITY_STATS = gql`
2020
query CommunityStats {
2121
communityStatsLatest {
22+
id
2223
totalContributors
2324
totalUserGroups
2425
totalSwipes
2526
}
2627
communityStats {
28+
id
2729
totalContributors
2830
totalUserGroups
2931
totalSwipes

community-dashboard/app/views/UserDashboard/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ import styles from './styles.css';
2626
const USER_STATS = gql`
2727
query UserStats($pk: ID!, $limit: Int!, $offset: Int!) {
2828
user(pk: $pk) {
29+
id
2930
userId
3031
username
3132
userInUserGroups(pagination: {limit: $limit, offset: $offset}) {
3233
count
3334
items {
35+
id
3436
userGroupId
3537
userGroupName
3638
membersCount
3739
}
3840
}
3941
}
4042
userStats(userId: $pk) {
43+
id
4144
stats {
4245
totalSwipes
4346
totalSwipeTime
@@ -54,7 +57,9 @@ const USER_STATS = gql`
5457
const FILTERED_USER_STATS = gql`
5558
query FilteredUserStats($pk: ID!, $fromDate: DateTime!, $toDate: DateTime!) {
5659
userStats(userId: $pk) {
60+
id
5761
filteredStats(dateRange: { fromDate: $fromDate, toDate: $toDate}) {
62+
id
5863
areaSwipedByProjectType {
5964
totalArea
6065
projectType

django/apps/existing_database/query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def get_community_stats() -> CommunityStatsType:
4141
total_user_groups=models.Count("user_group", distinct=True),
4242
)
4343
return CommunityStatsType(
44+
id="all",
4445
total_contributors=user_agg_data["total_users"] or 0,
4546
total_user_groups=user_group_agg_data["total_user_groups"] or 0,
4647
total_swipes=user_agg_data["swipes_sum"] or 0,
@@ -64,6 +65,7 @@ def get_community_stats_latest() -> CommunityStatsType:
6465
total_user_groups=models.Count("user_group", distinct=True),
6566
)
6667
return CommunityStatsType(
68+
id="last-30-days",
6769
total_contributors=user_agg_data["total_users"] or 0,
6870
total_user_groups=user_group_agg_data["total_user_groups"] or 0,
6971
total_swipes=user_agg_data["swipes_sum"] or 0,

django/apps/existing_database/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DateRangeInput:
2424

2525
@strawberry.type
2626
class CommunityStatsType:
27+
id: strawberry.ID
2728
total_swipes: int
2829
total_contributors: int
2930
total_user_groups: int
@@ -264,23 +265,33 @@ def __post_init__(self, date_range, user_id):
264265
filters = {
265266
"user_id": user_id,
266267
}
268+
self._user_id = user_id
267269
if date_range:
268270
filters.update(
269271
timestamp_date__gte=date_range.from_date,
270272
timestamp_date__lte=date_range.to_date,
271273
)
272274
self._qs = AggregatedUserStatData.objects.filter(**filters)
273275

276+
@strawberry.field
277+
async def id(self) -> strawberry.ID:
278+
return self._user_id
279+
274280

275281
@strawberry.type
276282
class UserStats:
277283
user_id: InitVar[str]
278284

279285
def __post_init__(self, user_id):
286+
self.id = user_id
280287
self._user_id = user_id
281288
self.qs = AggregatedUserStatData.objects.filter(user_id=user_id)
282289
self.ug_qs = AggregatedUserGroupStatData.objects.filter(user_id=user_id)
283290

291+
@strawberry.field
292+
async def id(self) -> strawberry.ID:
293+
return self._user_id
294+
284295
@strawberry.field
285296
async def stats(self) -> UserStatType:
286297
agg_data = await self.qs.aaggregate(

django/mapswipe/graphql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def _scope_with_sentry(self, execute_func, *args, **kwargs) -> ExecutionResult:
3939
operation_name = kwargs.get("operation_name")
4040
with sentry_sdk.configure_scope() as scope:
4141
scope.set_tag("kind", operation_name)
42-
scope.transaction.name = operation_name
42+
if scope.transaction:
43+
scope.transaction.name = operation_name
4344
return execute_func(*args, **kwargs)
4445

4546
def execute_sync(self, *args, **kwargs) -> ExecutionResult:

0 commit comments

Comments
 (0)