• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 13705230798

06 Mar 2025 06:06PM UTC coverage: 45.409% (-0.3%) from 45.755%
13705230798

Pull #11259

github

web-flow
Merge f98a8572f into 42b2201ae
Pull Request #11259: Added in async count cache

1313 of 3203 branches covered (40.99%)

Branch coverage included in aggregate %.

4 of 15 new or added lines in 4 files covered. (26.67%)

133 existing lines in 11 files now uncovered.

2510 of 5216 relevant lines covered (48.12%)

38.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/thread/GetThreadsByIds.query.ts
1
import {
2
  cache,
3
  CacheNamespaces,
4
  InvalidInput,
5
  Query,
6
} from '@hicommonwealth/core';
7
import { ThreadInstance } from '@hicommonwealth/model';
8
import * as schemas from '@hicommonwealth/schemas';
9
import { Op } from 'sequelize';
10
import { z } from 'zod';
11
import { models, sequelize } from '../database';
12

13
export function GetThreadsByIds(): Query<typeof schemas.GetThreadsByIds> {
14
  return {
×
15
    ...schemas.GetThreadsByIds,
16
    auth: [],
17
    secure: false,
18
    body: async ({ payload }) => {
19
      const { community_id, thread_ids } = payload;
×
20
      if (thread_ids === '') return [];
×
21

22
      let parsedThreadIds: number[];
23

24
      try {
×
25
        parsedThreadIds = z
×
26
          .string()
27
          .transform((ids) =>
28
            ids.split(',').map((id) => parseInt(id.trim(), 10)),
×
29
          )
30
          .parse(thread_ids);
31
      } catch (e) {
32
        throw new InvalidInput('Invalid thread_ids format');
×
33
      }
34

35
      let threads: ThreadInstance[];
NEW
36
      await models.sequelize.transaction(async (transaction) => {
×
NEW
37
        threads = await models.Thread.findAll({
×
38
          where: {
39
            ...(community_id && { community_id }),
×
40
            id: { [Op.in]: parsedThreadIds },
41
          },
42

43
          include: [
44
            {
45
              model: models.Address,
46
              as: 'Address',
47
              include: [
48
                {
49
                  model: models.User,
50
                  as: 'User',
51
                  required: true,
52
                  attributes: ['id', 'profile'],
53
                },
54
              ],
55
            },
56
            {
57
              model: models.Address,
58
              as: 'collaborators',
59
              include: [
60
                {
61
                  model: models.User,
62
                  as: 'User',
63
                  required: true,
64
                  attributes: ['id', 'profile'],
65
                },
66
              ],
67
            },
68
            {
69
              model: models.Topic,
70
              as: 'topic',
71
              required: true,
72
            },
73
            {
74
              model: models.Reaction,
75
              as: 'reactions',
76
              include: [
77
                {
78
                  model: models.Address,
79
                  as: 'Address',
80
                  required: true,
81
                  include: [
82
                    {
83
                      model: models.User,
84
                      as: 'User',
85
                      required: true,
86
                      attributes: ['id', 'profile'],
87
                    },
88
                  ],
89
                },
90
              ],
91
            },
92
            {
93
              model: models.ContestAction,
94
              where: {
95
                action: 'upvoted',
96
              },
97
              required: false,
98
              attributes: ['content_id', 'thread_id'],
99
              include: [
100
                {
101
                  model: models.Contest,
102
                  on: {
103
                    contest_id: sequelize.where(
104
                      sequelize.col('"ContestActions".contest_id'),
105
                      '=',
106
                      sequelize.col('"ContestActions->Contest".contest_id'),
107
                    ),
108
                    contest_address: sequelize.where(
109
                      sequelize.col('"ContestActions".contest_address'),
110
                      '=',
111
                      sequelize.col(
112
                        '"ContestActions->Contest".contest_address',
113
                      ),
114
                    ),
115
                  },
116
                  attributes: [
117
                    'contest_id',
118
                    'contest_address',
119
                    'score',
120
                    'start_time',
121
                    'end_time',
122
                  ],
123
                  include: [
124
                    {
125
                      model: models.ContestManager,
126
                      attributes: ['name', 'cancelled', 'interval'],
127
                    },
128
                  ],
129
                },
130
              ],
131
            },
132
            {
133
              model: models.ThreadVersionHistory,
134
            },
135
          ],
136
          transaction,
137
        });
138
      });
139

NEW
140
      for (const t of parsedThreadIds) {
×
NEW
141
        await cache().incrementKey(
×
142
          CacheNamespaces.Thread_View_Count,
143
          t.toString(),
144
        );
145
      }
146

NEW
147
      return threads!.map(
×
UNCOV
148
        (t) => t.toJSON() as z.infer<typeof schemas.ThreadView>,
×
149
      );
150
    },
151
  };
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc