This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save individual searches and result IDs in Postgres
- Loading branch information
1 parent
0965bd0
commit 59e8569
Showing
6 changed files
with
87 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 4.1.4 on 2023-01-17 07:16 | ||
|
||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0052_relational_fields'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Search', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now=True, help_text='The date the query was executed.')), | ||
('query_hash', models.CharField(help_text='The query hash generated by ``dead_link_mask.get_query_hash``.', max_length=256)), | ||
('query_params', models.JSONField(help_text='The query parameters used to execute the query.')), | ||
('results', django.contrib.postgres.fields.ArrayField(base_field=models.UUIDField(), help_text='List of result IDs for the query.', size=None)), | ||
('page', models.IntegerField(help_text='The page number of the request. Extracted from ``query_params`` for ease of querying.')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ | |
OAuth2Verification, | ||
ThrottledApplication, | ||
) | ||
from catalog.api.models.search import Search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from django.contrib.postgres.fields import ArrayField | ||
from django.db import models | ||
|
||
|
||
class Search(models.Model): | ||
|
||
""" | ||
An individual query with attached results. | ||
TODO(sarayourfriend): Which fields need indexes? :thinking: | ||
""" | ||
|
||
created_at = models.DateTimeField( | ||
auto_now=True, | ||
null=False, | ||
help_text="The date the query was executed.", | ||
) | ||
|
||
query_hash = models.CharField( | ||
# We use SHA256 which only needs 64, but we can leave | ||
# room for changes (maybe not necessary?) | ||
max_length=128, | ||
null=False, | ||
help_text=("The query hash generated by " "``dead_link_mask.get_query_hash``."), | ||
) | ||
|
||
query_params = models.JSONField( | ||
null=False, | ||
help_text="The query parameters used to execute the query.", | ||
) | ||
|
||
results = ArrayField( | ||
# Is this going to be a pain to join to retrieve the providers? | ||
# If we rely on this approach then we'd probably forever by reliant | ||
# on catalogue data being duplicated between ES and Postgres API. | ||
# Maybe that wouldn't be the case if we did weekly extractions | ||
# of the data from here into the catalogue DB and then did the joining | ||
# etc, over there? In that case, is there somewhere other than | ||
# Postgres we can keep the data? Is that option expedient (would we be | ||
# able to use it in a matter of a week or two so that we can actually | ||
# benefit from this w/r/t iNaturalist?) | ||
models.UUIDField(null=False), | ||
null=False, | ||
help_text="List of result IDs for the query.", | ||
) | ||
|
||
page = models.IntegerField( | ||
null=False, | ||
help_text=( | ||
"The page number of the request. " | ||
"Extracted from ``query_params`` for ease of querying." | ||
), | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters