Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Microservices
query-service
Commits
e5c41888
Commit
e5c41888
authored
3 months ago
by
Sjoerd Vink
Browse files
Options
Downloads
Patches
Plain Diff
feat(reportOnNewData): use hashing instead of dict
parent
1762b548
Branches
feat/reportOnNewData
No related tags found
No related merge requests found
Pipeline
#143169
passed
3 months ago
Stage: tag-release
Stage: get-release-tag
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/readers/queryService.ts
+15
-24
15 additions, 24 deletions
src/readers/queryService.ts
src/utils/hashing/index.ts
+20
-0
20 additions, 0 deletions
src/utils/hashing/index.ts
with
35 additions
and
24 deletions
src/readers/queryService.ts
+
15
−
24
View file @
e5c41888
...
...
@@ -24,6 +24,7 @@ import { parseCypherQuery } from "../utils/cypher/queryParser";
import
{
formatTimeDifference
}
from
"
ts-common/src/logger/logger
"
;
import
{
graphQueryBackend2graphQuery
}
from
"
../frontend/statistics
"
;
import
{
Query2BackendQuery
}
from
"
../utils/reactflow/query2backend
"
;
import
{
hashDictionary
,
hashIsEqual
}
from
"
../utils/hashing
"
;
export
const
queryService
=
async
(
db
:
DbConnection
,
query
:
string
):
Promise
<
GraphQueryResultMetaFromBackend
>
=>
{
// TODO: only neo4j is supported for now
...
...
@@ -287,16 +288,13 @@ export const queryServiceReaderDiffCheck = async (type: QueryExecutionTypes) =>
USER_MANAGEMENT_SERVICE_API
);
// const ssInsight = await getUserSaveStateInsight(
// headers.message.sessionData.userID,
// headers.message.sessionData.saveStateID,
// USER_MANAGEMENT_SERVICE_API
// );
const
previousQueryResult
=
{
nodes
:
[],
edges
:
[],
};
const
ssInsight
=
await
getUserSaveStateInsight
(
headers
.
message
.
sessionData
.
userID
,
headers
.
message
.
sessionData
.
saveStateID
,
USER_MANAGEMENT_SERVICE_API
);
// const previousQueryResult = ssInsight.previous_result_hash;
const
previousQueryResult
=
"
Get hash from db
"
;
log
.
debug
(
"
Received query request:
"
,
ss
);
...
...
@@ -331,21 +329,14 @@ export const queryServiceReaderDiffCheck = async (type: QueryExecutionTypes) =>
log
.
debug
(
"
Query result!
"
);
log
.
info
(
`Query executed in
${
formatTimeDifference
(
Date
.
now
()
-
startTime
)}
`
);
const
queryResult
=
{
const
queryResult
=
hashDictionary
(
{
nodes
:
result
.
nodes
.
map
((
node
)
=>
node
.
_id
),
edges
:
result
.
edges
.
map
((
edge
)
=>
edge
.
_id
),
};
// Compare query results
const
nodesDifferent
=
queryResult
.
nodes
.
some
((
node
,
index
)
=>
node
!==
previousQueryResult
.
nodes
[
index
]);
const
edgesDifferent
=
queryResult
.
edges
.
some
((
edge
,
index
)
=>
edge
!==
previousQueryResult
.
edges
[
index
]);
if
(
queryResult
.
nodes
.
length
!==
previousQueryResult
.
nodes
.
length
||
queryResult
.
edges
.
length
!==
previousQueryResult
.
edges
.
length
||
nodesDifferent
||
edgesDifferent
)
{
});
log
.
info
(
"
Comparing hash values from current and previous query
"
);
if
(
previousQueryResult
&&
!
hashIsEqual
(
queryResult
,
previousQueryResult
))
{
log
.
info
(
"
Different results, use Dennis code...
"
);
}
else
{
log
.
info
(
"
No difference in result sets
"
);
...
...
@@ -356,7 +347,7 @@ export const queryServiceReaderDiffCheck = async (type: QueryExecutionTypes) =>
headers
.
message
.
sessionData
.
userID
,
headers
.
message
.
sessionData
.
saveStateID
,
USER_MANAGEMENT_SERVICE_API
,
queryResult
{
previous_result_hash
:
queryResult
}
);
log
.
info
(
"
Updated node and edge ids in SaveState
"
);
...
...
This diff is collapsed.
Click to expand it.
src/utils/hashing/index.ts
0 → 100644
+
20
−
0
View file @
e5c41888
const
FNV_OFFSET_BASIS
=
2166136261
;
export
const
hashDictionary
=
(
dictionary
:
Record
<
"
nodes
"
|
"
edges
"
,
string
[]
>
):
string
=>
{
// Convert the dictionary into a consistent string format
const
jsonString
=
JSON
.
stringify
(
dictionary
,
Object
.
keys
(
dictionary
).
sort
());
// FNV-1a hash implementation
let
hash
=
FNV_OFFSET_BASIS
;
// FNV offset basis
for
(
let
i
=
0
;
i
<
jsonString
.
length
;
i
++
)
{
hash
^=
jsonString
.
charCodeAt
(
i
);
hash
+=
(
hash
<<
1
)
+
(
hash
<<
4
)
+
(
hash
<<
7
)
+
(
hash
<<
8
)
+
(
hash
<<
24
);
// FNV prime
}
// Convert hash to a hexadecimal string
return
(
hash
>>>
0
).
toString
(
16
);
// Ensure unsigned integer representation
};
export
const
hashIsEqual
=
(
hash1
:
string
,
hash2
:
string
):
boolean
=>
{
return
hash1
===
hash2
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment