Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

Commit 4ceb457

Browse files
committed
do not use list profiles for normal matching
1 parent 7eadd0e commit 4ceb457

4 files changed

Lines changed: 86 additions & 20 deletions

File tree

controller/ctx/ctx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *Ctx) GetOrGenMatcherProfilesCache() (*MatcherProfilesCache, error) {
4747

4848
// Update the cache
4949
c.Logger.Info("updating the profiles cache")
50-
scanProfiles, err := models.GetActualActiveProfiles(c.DBConn)
50+
scanProfiles, err := models.GetActualMatchActiveProfiles(c.DBConn)
5151
if err != nil {
5252
return nil, err
5353
}

controller/profiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var routeGetProfilesCount = routeBuilder.R{
6868
return err
6969
}
7070

71-
usableProfilesCount, err := models.GetActualActiveProfilesCount(ctx.DBConn)
71+
usableProfilesCount, err := models.GetActualMatchActiveProfilesCount(ctx.DBConn)
7272
if err != nil {
7373
return err
7474
}

models/profile.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ func (*Profile) Indexes() []mongo.IndexModel {
7878

7979
var isArrayWContent = bson.M{"$not": bson.M{"$size": 0}, "$type": "array"}
8080

81-
func actualActiveProfilesFilter() bson.M {
82-
return bson.M{
83-
"active": true,
84-
"$or": []bson.M{
85-
{"desiredProfessions": isArrayWContent},
86-
{"professionExperienced": isArrayWContent},
87-
{"driversLicenses": isArrayWContent},
88-
{"educations": isArrayWContent},
89-
},
90-
}
91-
}
92-
9381
// GetListsProfiles returns all profiles that can be used for the cv lists functionality
9482
func GetListsProfiles(conn db.Connection) ([]Profile, error) {
9583
profiles := []Profile{}
@@ -101,18 +89,32 @@ func GetListsProfiles(conn db.Connection) ([]Profile, error) {
10189
return profiles, err
10290
}
10391

104-
// GetActualActiveProfiles returns that we can actually use
92+
func actualActiveMatchProfilesFilter() bson.M {
93+
return bson.M{
94+
"active": true,
95+
"$or": []bson.M{
96+
{"desiredProfessions": isArrayWContent},
97+
{"professionExperienced": isArrayWContent},
98+
{"driversLicenses": isArrayWContent},
99+
{"educations": isArrayWContent},
100+
},
101+
// we use $not here as there are properties without this property and with `$not: true` we match `false`, `undefined` and `null
102+
"listsAllowed": bson.M{"$not": bson.M{"$eq": true}},
103+
}
104+
}
105+
106+
// GetActualMatchActiveProfiles returns that we can actually use
105107
// Matches are not really helpfull if no desiredProfessions, professionExperienced, driversLicenses or educations is set
106108
// Matches without an onMatch property are useless as we can't send the match anywhere
107-
func GetActualActiveProfiles(conn db.Connection) ([]Profile, error) {
109+
func GetActualMatchActiveProfiles(conn db.Connection) ([]Profile, error) {
108110
profiles := []Profile{}
109-
err := conn.Find(&Profile{}, &profiles, actualActiveProfilesFilter())
111+
err := conn.Find(&Profile{}, &profiles, actualActiveMatchProfilesFilter())
110112
return profiles, err
111113
}
112114

113-
// GetActualActiveProfilesCount does the same as GetActualActiveProfiles but only returns the number of found profiles
114-
func GetActualActiveProfilesCount(conn db.Connection) (uint64, error) {
115-
return conn.Count(&Profile{}, actualActiveProfilesFilter())
115+
// GetActualMatchActiveProfilesCount does the same as GetActualMatchActiveProfiles but only returns the number of found profiles
116+
func GetActualMatchActiveProfilesCount(conn db.Connection) (uint64, error) {
117+
return conn.Count(&Profile{}, actualActiveMatchProfilesFilter())
116118
}
117119

118120
// GetProfiles returns all profiles from the database

models/profile_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package models
2+
3+
import (
4+
"testing"
5+
6+
"github.com/script-development/RT-CV/db"
7+
"github.com/script-development/RT-CV/db/testingdb"
8+
. "github.com/tj/assert"
9+
)
10+
11+
func testProfilesSetupDB(t *testing.T) *testingdb.TestConnection {
12+
testingDB := testingdb.NewDB()
13+
14+
zipCodes := []ProfileDutchZipcode{{1000, 1999}}
15+
desiredProfessions := []ProfileProfession{{Name: "gangster"}}
16+
17+
err := testingDB.UnsafeInsert(
18+
&Profile{ // active list profile
19+
M: db.NewM(),
20+
Active: true,
21+
Zipcodes: zipCodes,
22+
DesiredProfessions: desiredProfessions,
23+
ListsAllowed: false,
24+
},
25+
&Profile{ // IN-active list profile
26+
M: db.NewM(),
27+
Active: false,
28+
Zipcodes: zipCodes,
29+
DesiredProfessions: desiredProfessions,
30+
ListsAllowed: false,
31+
},
32+
&Profile{ // active list profile
33+
M: db.NewM(),
34+
Active: true,
35+
Zipcodes: zipCodes,
36+
DesiredProfessions: desiredProfessions,
37+
ListsAllowed: true,
38+
},
39+
&Profile{ // IN-active list profile
40+
M: db.NewM(),
41+
Active: false,
42+
Zipcodes: zipCodes,
43+
DesiredProfessions: desiredProfessions,
44+
ListsAllowed: true,
45+
},
46+
)
47+
NoError(t, err)
48+
49+
return testingDB
50+
}
51+
52+
func TestGetActualMatchActiveProfiles(t *testing.T) {
53+
d := testProfilesSetupDB(t)
54+
profiles, err := GetActualMatchActiveProfiles(d)
55+
NoError(t, err)
56+
Len(t, profiles, 1)
57+
}
58+
59+
func TestGetListsProfiles(t *testing.T) {
60+
d := testProfilesSetupDB(t)
61+
profiles, err := GetListsProfiles(d)
62+
NoError(t, err)
63+
Len(t, profiles, 1)
64+
}

0 commit comments

Comments
 (0)