feat(assist): support null&empty values for search
feat(assist): changed single-session search feat(api): support null&empty values for live sessions search feat(api): support key-mapping for different names feat(api): support platform live-sessions search
This commit is contained in:
parent
6cc7372187
commit
f76c621350
6 changed files with 85 additions and 35 deletions
|
|
@ -22,7 +22,7 @@ SESSION_PROJECTION_COLS = """s.project_id,
|
|||
|
||||
def get_live_sessions_ws_user_id(project_id, user_id):
|
||||
data = {
|
||||
"filter": {"userId": user_id}
|
||||
"filter": {"userId": user_id} if user_id else {}
|
||||
}
|
||||
return __get_live_sessions_ws(project_id=project_id, data=data)
|
||||
|
||||
|
|
@ -73,18 +73,9 @@ def __get_live_sessions_ws(project_id, data):
|
|||
|
||||
|
||||
def get_live_session_by_id(project_id, session_id):
|
||||
all_live = __get_live_sessions_ws(project_id, data={"filter": {"sessionId": session_id}})
|
||||
for l in all_live:
|
||||
if str(l.get("sessionID")) == str(session_id):
|
||||
return l
|
||||
return None
|
||||
|
||||
|
||||
def is_live(project_id, session_id, project_key=None):
|
||||
if project_key is None:
|
||||
project_key = projects.get_project_key(project_id)
|
||||
project_key = projects.get_project_key(project_id)
|
||||
try:
|
||||
connected_peers = requests.get(config("assistList") % config("S3_KEY") + f"/{project_key}/{session_id}",
|
||||
connected_peers = requests.get(config("assist") % config("S3_KEY") + f"/{project_key}/{session_id}",
|
||||
timeout=config("assistTimeout", cast=int, default=5))
|
||||
if connected_peers.status_code != 200:
|
||||
print("!! issue with the peer-server")
|
||||
|
|
@ -103,7 +94,33 @@ def is_live(project_id, session_id, project_key=None):
|
|||
except:
|
||||
print("couldn't get response")
|
||||
return False
|
||||
return str(session_id) in connected_peers
|
||||
return connected_peers
|
||||
|
||||
|
||||
def is_live(project_id, session_id, project_key=None):
|
||||
if project_key is None:
|
||||
project_key = projects.get_project_key(project_id)
|
||||
try:
|
||||
connected_peers = requests.get(config("assistList") % config("S3_KEY") + f"/{project_key}/{session_id}",
|
||||
timeout=config("assistTimeout", cast=int, default=5))
|
||||
if connected_peers.status_code != 200:
|
||||
print("!! issue with the peer-server")
|
||||
print(connected_peers.text)
|
||||
return False
|
||||
connected_peers = connected_peers.json().get("data")
|
||||
except requests.exceptions.Timeout:
|
||||
print("Timeout getting Assist response")
|
||||
return False
|
||||
except Exception as e:
|
||||
print("issue getting Assist response")
|
||||
print(str(e))
|
||||
print("expected JSON, received:")
|
||||
try:
|
||||
print(connected_peers.text)
|
||||
except:
|
||||
print("couldn't get response")
|
||||
return False
|
||||
return str(session_id) == connected_peers
|
||||
|
||||
|
||||
def autocomplete(project_id, q: str, key: str = None):
|
||||
|
|
|
|||
|
|
@ -1018,6 +1018,7 @@ class LiveFilterType(str, Enum):
|
|||
user_id = FilterType.user_id.value
|
||||
user_anonymous_id = FilterType.user_anonymous_id.value
|
||||
rev_id = FilterType.rev_id.value
|
||||
platform = FilterType.platform.value
|
||||
page_title = "PAGETITLE"
|
||||
session_id = "SESSIONID"
|
||||
metadata = "METADATA"
|
||||
|
|
@ -1025,7 +1026,6 @@ class LiveFilterType(str, Enum):
|
|||
tracker_version = "TRACKERVERSION"
|
||||
user_browser_version = "USERBROWSERVERSION"
|
||||
user_device_type = "USERDEVICETYPE",
|
||||
timestamp = "TIMESTAMP"
|
||||
|
||||
|
||||
class LiveSessionSearchFilterSchema(BaseModel):
|
||||
|
|
@ -1043,13 +1043,26 @@ class LiveSessionSearchFilterSchema(BaseModel):
|
|||
|
||||
class LiveSessionsSearchPayloadSchema(_PaginatedSchema):
|
||||
filters: List[LiveSessionSearchFilterSchema] = Field([])
|
||||
sort: Union[LiveFilterType, str] = Field(default=LiveFilterType.timestamp)
|
||||
sort: Union[LiveFilterType, str] = Field(default="TIMESTAMP")
|
||||
order: SortOrderType = Field(default=SortOrderType.desc)
|
||||
|
||||
@root_validator(pre=True)
|
||||
def transform_order(cls, values):
|
||||
def transform(cls, values):
|
||||
if values.get("order") is not None:
|
||||
values["order"] = values["order"].upper()
|
||||
if values.get("filters") is not None:
|
||||
i = 0
|
||||
while i < len(values["filters"]):
|
||||
if values["filters"][i]["values"] is None or len(values["filters"][i]["values"]) == 0:
|
||||
del values["filters"][i]
|
||||
else:
|
||||
i += 1
|
||||
for i in values["filters"]:
|
||||
if i.get("type") == LiveFilterType.platform.value:
|
||||
i["type"] = LiveFilterType.user_device_type.value
|
||||
if values.get("sort") is not None:
|
||||
if values["sort"].lower() == "startts":
|
||||
values["sort"] = "TIMESTAMP"
|
||||
return values
|
||||
|
||||
class Config:
|
||||
|
|
|
|||
|
|
@ -136,7 +136,10 @@ const socketsListByProject = async function (req, res) {
|
|||
}
|
||||
}
|
||||
}
|
||||
respond(res, liveSessions[_projectKey] || []);
|
||||
liveSessions[_projectKey] = liveSessions[_projectKey] || [];
|
||||
respond(res, _sessionId === undefined ? liveSessions[_projectKey]
|
||||
: liveSessions[_projectKey].length > 0 ? liveSessions[_projectKey][0]
|
||||
: null);
|
||||
}
|
||||
|
||||
const socketsLive = async function (req, res) {
|
||||
|
|
@ -192,7 +195,10 @@ const socketsLiveByProject = async function (req, res) {
|
|||
liveSessions[projectKey] = uniqueSessions(liveSessions[projectKey] || []);
|
||||
}
|
||||
}
|
||||
respond(res, sortPaginate(liveSessions[_projectKey] || [], filters));
|
||||
liveSessions[_projectKey] = liveSessions[_projectKey] || [];
|
||||
respond(res, _sessionId === undefined ? sortPaginate(liveSessions[_projectKey], filters)
|
||||
: liveSessions[_projectKey].length > 0 ? liveSessions[_projectKey][0]
|
||||
: null);
|
||||
}
|
||||
|
||||
const autocomplete = async function (req, res) {
|
||||
|
|
|
|||
|
|
@ -118,7 +118,10 @@ const socketsListByProject = async function (req, res) {
|
|||
}
|
||||
}
|
||||
}
|
||||
respond(res, sortPaginate(liveSessions[_projectKey] || [], filters));
|
||||
liveSessions[_projectKey] = liveSessions[_projectKey] || [];
|
||||
respond(res, _sessionId === undefined ? sortPaginate(liveSessions[_projectKey], filters)
|
||||
: liveSessions[_projectKey].length > 0 ? liveSessions[_projectKey][0]
|
||||
: null);
|
||||
}
|
||||
|
||||
const socketsLive = async function (req, res) {
|
||||
|
|
@ -172,7 +175,10 @@ const socketsLiveByProject = async function (req, res) {
|
|||
}
|
||||
}
|
||||
}
|
||||
respond(res, sortPaginate(liveSessions[_projectKey] || [], filters));
|
||||
liveSessions[_projectKey] = liveSessions[_projectKey] || [];
|
||||
respond(res, _sessionId === undefined ? sortPaginate(liveSessions[_projectKey], filters)
|
||||
: liveSessions[_projectKey].length > 0 ? liveSessions[_projectKey][0]
|
||||
: null);
|
||||
}
|
||||
|
||||
const autocomplete = async function (req, res) {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,10 @@ const socketsListByProject = async function (req, res) {
|
|||
}
|
||||
}
|
||||
}
|
||||
respond(res, liveSessions[_projectKey] || []);
|
||||
liveSessions[_projectKey] = liveSessions[_projectKey] || [];
|
||||
respond(res, _sessionId === undefined ? liveSessions[_projectKey]
|
||||
: liveSessions[_projectKey].length > 0 ? liveSessions[_projectKey][0]
|
||||
: null);
|
||||
}
|
||||
|
||||
const socketsLive = async function (req, res) {
|
||||
|
|
@ -152,7 +155,10 @@ const socketsLiveByProject = async function (req, res) {
|
|||
}
|
||||
}
|
||||
}
|
||||
respond(res, sortPaginate(liveSessions[_projectKey] || [], filters));
|
||||
liveSessions[_projectKey] = liveSessions[_projectKey] || [];
|
||||
respond(res, _sessionId === undefined ? sortPaginate(liveSessions[_projectKey], filters)
|
||||
: liveSessions[_projectKey].length > 0 ? liveSessions[_projectKey][0]
|
||||
: null);
|
||||
}
|
||||
|
||||
const autocomplete = async function (req, res) {
|
||||
|
|
|
|||
|
|
@ -42,22 +42,24 @@ const isValidSession = function (sessionInfo, filters) {
|
|||
let foundAll = true;
|
||||
for (const [key, values] of Object.entries(filters)) {
|
||||
let found = false;
|
||||
for (const [skey, svalue] of Object.entries(sessionInfo)) {
|
||||
if (svalue !== undefined && svalue !== null) {
|
||||
if (typeof (svalue) === "object") {
|
||||
if (isValidSession(svalue, {[key]: values})) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
} else if (skey.toLowerCase() === key.toLowerCase()) {
|
||||
for (let v of values) {
|
||||
if (String(svalue).toLowerCase().indexOf(v.toLowerCase()) >= 0) {
|
||||
if (values !== undefined && values !== null) {
|
||||
for (const [skey, svalue] of Object.entries(sessionInfo)) {
|
||||
if (svalue !== undefined && svalue !== null) {
|
||||
if (typeof (svalue) === "object") {
|
||||
if (isValidSession(svalue, {[key]: values})) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
} else if (skey.toLowerCase() === key.toLowerCase()) {
|
||||
for (let v of values) {
|
||||
if (String(svalue).toLowerCase().indexOf(v.toLowerCase()) >= 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue