GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update database to include all questions · ServiceStackApps/StackApis@8d42f97

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • StackApis.Tests
      • UnitTests.cs
    • StackApis/App_Data
      • db.sqlite
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/StackApis.Tests/UnitTests.cs‎

Copy file name to clipboardExpand all lines: src/StackApis.Tests/UnitTests.cs
+32-25Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,48 @@ public void TestImport()
6767
private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
6868
{
6969
var client = new JsonServiceClient();
70-
int numberOfPages = 5;
70+
int numberOfPages = 70;
7171
int pageSize = 100;
7272
var dbQuestions = new List<Question>();
7373
var dbAnswers = new List<Answer>();
74-
for (int i = 1; i < numberOfPages + 1; i++)
74+
try
7575
{
76-
//Throttle queries
77-
Thread.Sleep(500);
78-
var questionsResponse =
79-
client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
80-
.Fmt(i, pageSize, "stackoverflow"));
81-
82-
QuestionsResponse qResponse;
83-
using (new ConfigScope())
76+
for (int i = 1; i < numberOfPages + 1; i++)
8477
{
85-
var json = questionsResponse.ReadToEnd();
86-
qResponse = json.FromJson<QuestionsResponse>();
87-
dbQuestions.AddRange(qResponse.Items.Select(q => q.ConvertTo<Question>()));
88-
}
78+
//Throttle queries
79+
Thread.Sleep(500);
80+
var questionsResponse =
81+
client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
82+
.Fmt(i, pageSize, "stackoverflow"));
83+
84+
QuestionsResponse qResponse;
85+
using (new ConfigScope())
86+
{
87+
var json = questionsResponse.ReadToEnd();
88+
qResponse = json.FromJson<QuestionsResponse>();
89+
dbQuestions.AddRange(qResponse.Items.Select(q => q.ConvertTo<Question>()));
90+
}
8991

90-
var acceptedAnswers =
91-
qResponse.Items
92-
.Where(x => x.AcceptedAnswerId != null)
93-
.Select(x => x.AcceptedAnswerId).ToList();
92+
var acceptedAnswers =
93+
qResponse.Items
94+
.Where(x => x.AcceptedAnswerId != null)
95+
.Select(x => x.AcceptedAnswerId).ToList();
9496

95-
var answersResponse = client.Get("https://api.stackexchange.com/2.2/answers/{0}?sort=activity&site=stackoverflow"
96-
.Fmt(acceptedAnswers.Join(";")));
97+
var answersResponse = client.Get("https://api.stackexchange.com/2.2/answers/{0}?sort=activity&site=stackoverflow"
98+
.Fmt(acceptedAnswers.Join(";")));
9799

98-
using (new ConfigScope())
99-
{
100-
var json = answersResponse.ReadToEnd();
101-
var aResponse = JsonSerializer.DeserializeFromString<AnswersResponse>(json);
102-
dbAnswers.AddRange(aResponse.Items.Select(a => a.ConvertTo<Answer>()));
100+
using (new ConfigScope())
101+
{
102+
var json = answersResponse.ReadToEnd();
103+
var aResponse = JsonSerializer.DeserializeFromString<AnswersResponse>(json);
104+
dbAnswers.AddRange(aResponse.Items.Select(a => a.ConvertTo<Answer>()));
105+
}
103106
}
104107
}
108+
catch (Exception ex)
109+
{
110+
//ignore
111+
}
105112

106113
//Filter duplicates
107114
dbQuestions = dbQuestions.GroupBy(q => q.QuestionId).Select(q => q.First()).ToList();
Collapse file

‎src/StackApis/App_Data/db.sqlite‎

Copy file name to clipboard
2.15 MB
Binary file not shown.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.